Icon
Icon
Icon
Icon
Icon
Icon

Improved Object Dereferencing Support

12:31 AM
0 comments


Overview
Support the de-referencing of objects returned from methods, e.g.                         
$object->method()->method()  (this change will possibly also include the ability to de-
reference objects returned from functions, i.e.  func()->method()->method()). (This
feature  would  also  include  something  more  complicated  like                             
$object->method()->member->method() where a returned object’s member is an object
itself and then one of its methods is called).
Background
Due to the previous object model it is not possible to de-reference returned objects. This
support was not implemented because it was not technically feasible.
Need
Many PHP developers have asked for the possibility to de-reference returned objects. Not
only will this often lead to better-looking code but it can also prevent certain
programming errors.
With the old object model, the equivalent of  $object->method()->method()->method()
would be:
$tmp =& $object->method();
$tmp =& $tmp->method();
$tmp->method();

Also, when interfacing with Java or COM objects, this is the natural syntax to use.
Overview
Thanks to the new object model, as well as the improved parser, it will be possible to call
methods directly on a object handle that is returned from a function.  Due to the nature of
the new model, the method will be called on the very same object, and not on a different
replica. Functionality
With this feature one will be able to nicely de-reference returned objects as the following
code shows:

$object->method()->method()->member = 5;

Due to the fact that in the middle of this expression handles to objects are returned and
not the objects themselves, if the methods are written correctly the right objects are
always manipulated.
Compatibility notes
As this syntax does not exist in previous versions of the Zend Engine there are no
compatibility impacts.
Dependencies of feature
This feature is dependent upon the new object model of the Zend Engine 2.0.

If You Enjoyed This Post Please Take a Second To Share It.

You Might Also Like

Stay Connected With Free Updates

Subscribe via Email

teaser