Ref class

This very small class helps keeping references to objects even while modifying arrays or passing non reference arguments.

You can have many copy of a Ref object, each copy will reference the same source object.

Until ZendEngine2, it is safer to use Ref objects in stead of php object references.

Important :

This object will have no meaning in php 4.4 as PHP will then use references everywhere objects are involved.

Creating a reference

$a = new SomeObject();
$ref = new Ref($a);

As a Ref mustn't reference another Ref (unless explicitely specified), referencing a Ref object create a copy of this Ref.

$a = new SomeObject();
$r1 = new Ref($a);          // $r1->obj === $a
$r2 = new Ref($r1);         // $r2->obj === $r1->obj === $a

Accessing the source object

The source object can be retrieved through the 'obj' attribute of the Ref object.

$a = new SomeObject();
$ref = new Ref($a);

// calls doFoo() on $a
$ref->obj->doFoo();