( I’m publishing this partially done so that it acts as a reminder for me to FINISH it… bare with me! )
Overview of Important Changes
variable class naming
Previously in PHP, only method and function names could be variables. Ie:
$func = "print";
$func("Hello World");
class Foo {
public static function Bar()
{
echo "Hello World";
}
}
$method = "Bar";
Foo::$method();
Now, in PHP 5.3+, variable class naming is also supported – making possible this syntax:
class Foo {
public static function Bar()
{
echo "Hello World";
}
}
$class = "Foo";
$method = "Bar";
$class::$method
This new class variable naming should provide a much desired level of ambiguity for PHP developers, I know for my MVC framework, it could really change the Typhoon PHP Typhoon->run() method in a positive way.
late static binding
This is a more advance PHP OOP topic – that almost came off as a bug in previous versions of PHP. I’ve personally ran into it myself on occasion, and am happy to see a solution available in PHP 5.3. In previous versions of PHP, static calls resolved to the inherited class. In cases where one needed a static call to resolve in it’s own scope, unexpected results were common. Ie:
class Foo { public static function who() { echo __CLASS__; } public static function test() { self::who(); } } class Bar extends Foo { public static function who() { echo __CLASS__; } } Bar::test();
Output:
Foo
The solution, “Late Static Bindings”, solves this using the static keyword:
class Foo {
public static function who() {
echo __CLASS__;
}
public static function test() {
static::who();
}
}
class Bar extends Foo {
public static function who() {
echo __CLASS__;
}
}
Bar::test();
The static keyword resolves to the calling class and produces the expected output:
Bar
Additions to Standard PHP Library (SPL)
Circular Garbage Collection
Lambda Functions (Anonymous Functions)
Closures
Overriding Internal Functions
New Reserved Words
Namespaces
Jump Labels
Changes to Functions and Methods
Extensions
Phar
php.ini Changes
Deprecated Methods
Install php 5.3 on Ubuntu
mkdir download && cd download wget http://snaps.php.net/php5.3-200906131830.tar.gz