PHP 4.0 Bug #7482: this is not reference in class constructor: Bug 6896 extension/correction

From: Date: Thu, 26 Oct 2000 15:14:05 +0000
Subject: PHP 4.0 Bug #7482: this is not reference in class constructor: Bug 6896 extension/correction
Groups: php.dev 
Request: Send a blank email to php-dev+get-36077@lists.php.net to get a copy of this message
From: danjrod@terra.es Operating system: RedHat Linux-6.2 PHP version: 4.0.3pl1 PHP Bug Type: Class/Object related Bug description: this is not reference in class constructor: Bug 6896 extension/correction Bug 6896 (suspended) states: 'a class cannot have a reference to its instance' The real problem lies within the constructor. If you try using a this as reference in the constructor you will get a copy. If you use this as a reference in any other member function it will work. Snippet below!. My guess: Temp object is created during object construction and this is 'this'. Then copy is made to be returned and 'temp' is deleted unless you have made a reference to temp. No specific setup. I simply want to pass this by reference to other objects. It won´t work from the class constructor. I have checked mail archives ./configure --with-mysql php.ini is default. script reproducing the problem 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"); // uncommenting this solves the problem // $l->add( $a1); $a1->set( "27"); $a2 = new t1_t( $l, "7"); $l->html(); // output should read 5 and 27 but it says 5 and 7. ?> -- Edit Bug report at: http://bugs.php.net/?id=7482&edit=1

« previous php.dev (#36077) next »