Hi:
I try using "this" inside a class' constructor to pass a reference to the new object to a second object.
It isn´t working (PHP4.0.3pl2) as I am getting a copy of the object instead of a reference.
If I do the same from any other member function it works fine.
Should it be this way ? Is it documented ? I wanted to do this to minimize the number of calls needed for objects to register into object lists.
The following code shows the problem:
The output should be:
starting
27
7
ending
But instead you get
starting
5
7
ending
<?php
class t1_t {
var $a;
function t1_t( &$p, $a) {
$this->a = $a;
$p->add( $obj);
}
function set( $a) {
$this->a = $a;
}
function get() {
return $this->a;
}
}
class testing_t {
var $obj;
function testing_t() {
$this->obj = array();
}
function add( &$obj) {
$this->obj[] = &$obj;
}
function html() {
echo "starting<br>\n";
reset( $this->obj);
while( list( $i, $obj) = each( $this->obj)) {
echo $obj->get() . "<br>\n";
}
echo "ending<br>\n";
}
}
$l = new testing_t();
$a1 = new t1_t( $l, "5");
$a2 = new t1_t( $l, "7");
$a1->set( "27");
$l->html();
?>