#33370 [Opn->Bgs]: PHP does not create references to $this
| From: | derick@php.net | Date: | Thu, 16 Jun 2005 20:25:29 +0000 |
| Subject: | #33370 [Opn->Bgs]: PHP does not create references to $this | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-80488@lists.php.net to get a copy of this message | ||
ID: 33370
Updated by: derick@php.net
Reported By: borysf at wp dot pl
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Windows, Linux
PHP Version: 4.4.0RC1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You are creating the copy here:
$this->Parent = $parent;
Previous Comments:
------------------------------------------------------------------------
[2005-06-16 22:22:50] borysf at wp dot pl
Description:
------------
There is a bug in creating references (This problem does not exist in
PHP5). If you have, for example, two classes and the first class
creates second and passes itself as reference to second's constructor,
reference is not being created. I've been trying to create this
reference in many ways, but always with the same result - there is no
reference, only a copy of class which was passed as reference.
Reproduce code:
---------------
class B {
var $Parent;
function B(&$parent) {
$this->Parent = $parent;
$this->Parent->Data = 'foo';
}
}
class A {
var $Data;
var $B;
function A() {
$this->B = new B($this);
}
}
$a = new A;
echo $a->Data;
Expected result:
----------------
echo should return 'foo', but returns nothing. In php5 it works
properly. Note, that I have used the & operator in B's constructor to
create a reference to A class.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33370&edit=1