Via PHPEverywhere, an initial release of the Zend Engine 2.0. For those who don't know, Zend is the engine which is the basis for PHP.
New stuff:
- New Object Model
- Private Members
- Object Cloning
- Forced deletion of objects
- Nested classes (namespaces)
- Classes may contain classes
- Classes may contain constants
- Current namespace's symbol tables are searched first for constants and functions
- In the scope of a function, the current namespace is that of the containing class/namespace
- It is possible to "import" symbols from one namespace into another
- Unified Constructors
- Destructors
- Exceptions
- Dereferencing objects returned from functions
- Static member variables of static classes can now be initialized
- Parameters that are passed by reference to a function may now have default values
- Built-In Backtracing
I just copied the major bullet points from the changes file. I gotta read everything in detail and understand what exactly has changed. They have examples of some of the new code you can use. One of the nice things is that you can dereference an object returned from a function, as in this snippet, which you just couldn't do before:
<?php
ShapeFactoryMethod("Circle")->draw();
ShapeFactoryMethod("Square")->draw();
#and you can even do it multiple times
print $person->getName()->display();
?>
Other nice things, exceptions, namespaces (a class can act as a namespace (its own scope), so you have more flexibility with scoping than we did before. You can refer to variables in your namespace by typing self::$variable_name, and import names from one namespace to another. That's great! - much better way to package reusable code), you can do stuff like this:
<?php
#reference argument has a default value!
function my_function(&$var = null) {
?>
All good news. As you can see, most of the changes have to do with their object model, which was pretty much broken in all previous versions of PHP. I almost never used classes - now maybe I will, and exceptions, and namespaces, and on and on. PHP's almost all growed up <sniff>.
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):