The PHP 5.4 is now available.
As you probably know, the updates that were intended for postponed PHP 6 were added to PHP 5.4.0 instead, so now PHP includes a huge set of new language features and removes several legacy behaviors.
Because of that I created a list of major changes since PHP 5.3 ,along with some examples and brief descriptions of these changes…
Major PHP improvements
Changes since PHP 5.3 version include:
Added class member access on instantiation. Now you can use fluent interfaces like in Java:
$myCar = (new Car)->setSpeed(100)->setColor('blue');
Added callable typehint. This typehint allows a string with a function name, a closure, and an array composed of classname (or object) with method name.
<?php function foo(callable $cb) {
$cb();
} ?>
Added closure rebinding as parameter to bindTo. Closure::bindTo() has been modified so now it accepts another argument that defines the new scope. This can either be an object if its class is used as the scope, or a class name.
Added support for Traits. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.
class Base { publicfunction sayHello() {
echo 'Hello ';
}
}
foreach ($callbacks as $k => $callback) {
if (is_callable($callback)) {
$callback($k);
}
}
Result:
Hello, 0
Hello, 1
Hello, 2
Changed $GLOBALS into a JIT autoglobal.$GLOBALS array is initialized only if it’s used. This is a performance/memory optimization, it can however break some of the existing scripts or opcode caches.
Improved performance of @ (silence) operator. This can speed up PHP scripts which rely heavily on a silence operator, for example:
$x = @file_get_contents('/etc/passwd');
echo $x;
Added multibyte support by default. Previously php had to be compiled with –enable-zend-multibyte. Now it can be enabled or disabled through zend.multibyte directive in php.ini.
Added built-in web server that is intended for testing purpose. The following command will open a web server on the port 8000.
php -S localhost:8000
Lots of performance and memory usage improvements
Removed major PHP features
Removed break/continue $var syntax. You can no longer use variable to tell PHP how many levels of enclosing loops it should skip to the end of.
Removed safe mode and all related ini options. Functionality described in this article and marked as depreciated in PHP 5.3 has now been removed
Removed register_globals and register_long_arrays ini options. If enabled, register_globals injected PHP scripts with all sorts of variables, like request variables from HTML forms or values from GET requests. Now, every request/environment variable must be fetched from an appropriate PHP array.
Removed allow_call_time_pass_reference option. Passing arguments by reference at function call time was deprecated for code-cleanliness reasons. A function can modify its arguments in an undocumented way if it didn’t declare that the argument shall be passed by reference. To prevent side-effects it’s better to specify which arguments are passed by reference in the function declaration only.
For a full list of changes in PHP 5.4, see the ChangeLog. For source downloads please visit php.net QAT downloads page, Windows binaries can be found here.