Language:EN
Pages: 37
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
and the base for the zend engine note

And the base for the zend engine note

Zend Engine Version 2.0

Overview

Version 1.0 of the Zend Engine is the heart and brain of PHP 4.0. It provides the infrastructure and services to the function modules, and implements the language syntax. The Zend Engine 1.0 is actually the second revision of the PHP scripting engine; It’s still at large based on the same parsing rules as the PHP 3.0 engine (which was basically ‘Zend Engine 0.5’). While this allowed for a very easy migration path from PHP 3.0 to 4.0, it also limited the scope of language-level improvements, to the same ‘state of mind’ as PHP 3.0 was in.

Background

In the Zend Engine 1.0 (and its predecessor the PHP 3 scripting engine) the object model’s design is that instantiated objects are language values. This means that when programmers are performing operations, such variable assignment and passing parameters to functions, objects are handled very similarly to the way other primitive types are handled such as integers and strings. Semantically this means that the whole object is being copied. The approach Java takes is different where one refers to objects by handle and not by value (one can think of a handle as an objects’ ID).

Functionality

After this change the basic use of objects will be almost identical to previous versions of the scripting engine. However, you won’t bump into awkward and confusing copying & destructing of objects.

2 {

3 function setMember($value)

8 }

function getMember()

9

{

10
11
12

15 {

16 $obj->setMember(“foo”);

21 foo($object);

22 print $object->getMember();

$obj->setMember(“foo”) call being called on a duplicate of $object. Line 22 will then

result in “bar” being printed.

Many PHP programmers aren’t even aware of the copying quirks of the current object model and, therefore, there is a relatively good chance that the amount of PHP applications that will work out of the box or after a very small amount of modifications would be high.

To simplify migration, version 2.0 will support an optional ‘auto-clone’ feature, which will perform a cloning of the object whenever it would have been copied in version 1.0. Optionally, it will also be possible to request that the engine will emit an E_NOTICE message whenever such an automatic clone occurs, in order to allow developers to gradually migrate to the version 2.0-style behavior (without automatic clones).

Background

Because of the underlying implementation, returning objects from functions in the Zend Engine 1.0 is very cumbersome. It is necessary to use special notation, $foo = &bar(), if one wishes to have bar() return an object by reference. Additionally, it’s also not possible to return an object by reference, by assigning it to a passed-by-reference argument, due to the copying semantics that characterizes the existing object model.

Functionality

Returning objects will be done in exactly the same way as any other primitive types (such

2 {

3 switch ($class_type) {

8 $obj = new MyBar();

9 break;

12 }
13

15 $object = FactoryMethod(“foo”);

With the new object model this code will return the object itself; It will create an instance

additional reference to itself. With the new model the object will still be returned

correctly. With the previous object model, when returning $obj it might have only been

Taking the same example, if the returned object weren’t returned via the return value but via a function argument you would bump into very similar problems. Consider the following function prototype for the previous function:
function FactoryMethod($object_type, &$resulting_object)

When trying to assign the created object to $resulting_object there might be strange behavior in the same cases as mentioned above. With the new model you can happily assign the object handle to $resulting_object and the instantiated object will be able to be referenced on the outside.

Improved Object Dereferencing Support

Overview

Support the de-referencing of objects returned from methods, e.g.
feature would also include something more complicated like

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.

Functionality

With this feature one will be able to nicely de-reference returned objects as the following code shows:

Dependencies of feature

This feature is dependent upon the new object model of the Zend Engine 2.0.

Creating a copy of an object with fully replicated properties is not always the wanted behavior. A good example of the need for copy constructors, is if you have an object which represents a GTK window and the object holds the resource of this GTK window, when you create a duplicate you might want to create a new window with the same properties and have the new object hold the resource of the new window.

Another example is if your object holds a reference to another object which it uses and when you replicate the parent object you want to create a new instance of this other object so that the replica has its own separate copy.

Compatibility notes

If by chance an object from an older script already has a method __clone() defined then it might be called not in a way the developer had planned. This should be quite easy to detect and work around.

No mechanism for object destructors exist today although PHP has support for registering functions which should be run on request shutdown.

Need

object is destroyed the object’s destructor is called before the object is freed from memory. Due to the nature of PHP such functionality still needs to be evaluated closely.

For example, when fatal errors occur it might not be possible to call object’s destructors or objects which are in a referential loop which the reference counting mechanism can’t

So it would look something like:

class MyClass
{
function __destruct()
{
… // Run destructor code }
}

This feature is dependent on the new object model.

delete statement

Overview

The proposed delete statement will address this problem. It will call the object’s destructor and free it even if the object is referenced by some other places in the engine. Other references to the deleted object will become stale and trying to access them will result in a fatal error.

Compatibility notes

No compatibility issues, as this feature doesn’t exist in previous versions of the scripting engine.

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Ricky Mason

PageId: ELI9819BAF