Icon
Icon
Icon
Icon
Icon
Icon
12:41 AM
0 comments


Revamped OO Syntax Overloading
Background
PHP 4.0 introduced the concept of overloading the object oriented syntax of the
language, to manipulate external objects and/or components, such as COM components
or Java objects.  This feature allowed to implement the interface to OO facilities in a
much more intuitive way, compared to the old procedural interface that was the only
option in PHP 3.0.

However, the implementation of Zend Engine 1.0’s OOSO (as found in PHP 4.0) is
limited in several ways, and is relatively difficult to program for.
The limitations and difficulties:
1.  Due to the Zend Engine 1.0’s parser limitations, it’s not always possible to write a
valid expression that corresponds to a desired behavior.  For instance, $foo-
>bar()->baz = 5;
which corresponds to an expression that makes sense in both COM and Java, is
not a valid Zend expression.
2.  The performance of the overloading mechanism is relatively low, because the
Zend Engine maintains a complete ‘parse tree’ for every overloaded expression
during execution.
3.  Implementing an OOSO module is difficult, because it later on has to traverse the
above parse tree to perform all of the necessary operations.
4.  An OOSO module must overload the entire object;  It’s impossible to overload
only parts of an object, and have the other parts behave as standard Zend objects.

Need
The above deficiencies are mostly notable in PHP 4.0’s lacking Java implementation,
which is both limited and difficult to debug.  It’s also very much noticeable in the new
PHP-GTK extension, which is gaining popularity rapidly;  PHP-GTK is greatly harmed
by all of the deficiencies mentioned in section 2.1, especially 2.1.1 and 2.1.4. Overview
The Zend Engine 2.0 will feature a new interface to OOSO, that will address all of the
issues mentioned in section 2.1.  The idea is to neglect the approach of developing a parse
tree at run-time, and passing it on to the OOSO module for resolution;  Instead, the Zend
Engine will allow specific mini-operations (fetching, assignment and method calling) to
be overloaded separately at each stage.  This will:
•  Simplify development of OOSO modules
•  Allow overloaded object to contain both other overloaded objects, or standard
Zend values (zval’s).
Significantly improve performance, as overloaded operations will occur just in time, at
the same stage as the standard Zend fetching/writing/method calling operations would
have occurred.
Functionality
The new OOSO modules will help make overloaded interfaces more intuitive to write for
module developers;  Perhaps more importantly, relying on the syntax improvements that
are scheduled for the Zend Engine 2.0, the new OOSO modules will allow complete
syntax compatibility between object models such as COM and Java, and Zend Engine
expressions.
Compatibility Notes
End users should experience no compatibility issues;  The new API will allow for
modules which support the same functionality as the old ones, along with some new
functionality (such as $foo->bar()->baz support).  It will, however, be necessary to
rewrite all of the existing OOSO modules to implement the new API.
Dependencies
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