New Features in PHP 5.4

This subject New Features in PHP 5.4 is not new as PHP 5.4 was released on March 1, 2012, But many of us still do not know what are the New features in php 5.4, So lets get familiar with them .

Why should I upgrade to 5.4 ? So What’s new Features in PHP 5.4 ?

So before going any further i will give you a very obvious reason of them all which is performance and security 🙂

Performance and Security

So in every new version weather it is PHP or Java they give significant improvements to the performance and security of your application and system, Therefor this is the only reason to update everything and be up to date on always .

What are Traits in PHP

Traits is a mechanism which help in the code reuse and solve the universal problem of multiple inheritance .

To have a very basic overview and tutorial of traits you can have a look on one of my another article here : http://www.technofusions.com/what-are-traits-in-php/

New syntax for arrays in PHP

Previously we used to create arrays like this:

Now you can create arrays with less code and  cleaner syntax:

The behavior and working is exactly the same . But  if you’re like the new syntax, you can go with the old syntax which still works.

If you want a basic tutorial on arrays you can go to the following link : http://www.technofusions.com/introduction-to-arrays-in-php/

De-referencing of Function arrays in PHP

If you are working with a php function which returns arrays, we put the result in a variable then access its index value .

Now we access the array like this

Now you can access the content directly in the function call according to new features in php:

This works for any  function or method that will return .

As you know, this is a shortest form of printing something in PHP:

But Now there is another way 🙂

This syntax also worked even before version 5.4, but to enable this “short_open_tags” was to be activated in php.ini, but now this syntax is enabled regardless of any settings in php.ini.

Access during instancing

Much like the access to the array indexes, this new feature allows you to access attributes and methods of objects being instantiated during instancing:

// How can create an instance and call function now

If you want to go for Official new features in php 5.4 go to this link:  http://www.php.net/manual/en/migration54.new-features.php

Leave a Reply

Your email address will not be published. Required fields are marked *