New Features in php 5.4


Features of PHP 5.4 are given below:

Traits
Traits are the most famous innovation in PHP 5.4: they consist in code fragments (a set of methods) that can be reused horizontally across classes.
Moreover, traits have a conflict resolution mechanism: multiple traits can be used in the same class even if some method names are overlapping.

Arrays improvements: syntax and dereferencing

class A
{
    public function foo()
    {
      return new B();
    }
}

class B
{
    public function bar()
    {
      return "Hi";
    }
}
$a = new A();
echo $a->foo()->bar(); // Will output Hi

Added indirect method call through array
Now an array(‘class’, ‘method’) can be used to call a function. is_callable will return true.

class Foo {
   public function bar($name) {
      echo "Hi, $name";
   }
}
$f = array('Foo','bar');
echo $f('chandan'); // Hi, chandan

Built-in HTTP server
As of PHP 5.4.0, the CLI SAPI provides a built-in web server.
This web server is designed for developmental purposes only, and should not be used in production.

Deprecations
PHP is being modernized by taking away (with backwards incompatibility) some old features which promote spaghetti code, and including new constraints.

  • Magic quotes options have been dropped.
  • The PHP namespace is now reserved for native code.
  • E_STRICT errors, covering for example correct usage of object-oriented constructs and deprecation warnings, are now covered by E_ALL. error_reporting(E_ALL) will show you really every error, warning and notice.

Upload progress

<form action=”upload.php” method=”POST” enctype=”multipart/form-data”>

<input type=”hidden” name=”” value=”testupload” />

<input type=”file” name=”file1″ />

<input type=”file” name=”file2″ />

<input type=”submit” />

</form>

which allows you to poll the server multiple times and get back info about the progress (in this case from $_SESSION[“upload_progress_ testupload “]).

Option to disable POST data processing
The ability to disable POST data processing to save memory and CPU cycles – in case it is activated, raw data can still be read through the php://input stream.

Advertisements

3 thoughts on “New Features in php 5.4

  1. Pingback: Goozle Zone

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s