PHP 4.0 Bug #3223: assignment of a returned reference to an object destroys a property
| From: | phaethon at phaethon dot ch | Date: | Sun, 16 Jan 2000 11:52:27 +0000 |
| Subject: | PHP 4.0 Bug #3223: assignment of a returned reference to an object destroys a property | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-14673@lists.php.net to get a copy of this message | ||
From: phaethon@phaethon.ch
Operating system: Linux 2.0
PHP version: 4.0 Latest CVS (16/01/2000)
PHP Bug Type: Scripting Engine problem
Bug description: assignment of a returned reference to an object destroys a property
class class1 {
var $class2;
var $foo = 'bar';
function class1 () {
$this->class2 = new class2 ($this);
}
function &get_ref_to_class2 () {
return $this->class2;
}
}
class class2 {
var $ref_to_class1;
function class2(&$ref_to_class1) {
$this->ref_to_class1 = &$ref_to_class1;
}
}
eval("\$c1 = new class1;");
/* here it is important, that this assignment is *not * done in the main_op_array, but (for example)
in an eval op_array or in an op_array of a function, like the following (otherwise, the bug
won't appear):
function make_c1 () {
global $c1;
$c1 = new class1;
}
make_c1();
*/
/* so now, let's test the stuff */
if(isset($c1->class2->ref_to_class1))
echo "isset(\$c1->class2->ref_to_class1) is TURE\n";
else echo "isset(\$c1->class2->ref_to_class1) is FALSE\n";
echo "\$c1->class2->ref_to_class1->foo is ";
echo $c1->class2->ref_to_class1->foo, "\n<hr>";
/* everything should be ok so far */
$c2 = &$c1->get_ref_to_class2(); /* critical ...
this seems to `destroy' ref_to_class1 */
/* the same tests again */
if(isset($c1->class2->ref_to_class1))
echo "isset(\$c1->class2->ref_to_class1) is TURE\n";
else echo "isset(\$c1->class2->ref_to_class1) is FALSE\n";
echo "\$c1->class2->ref_to_class1->foo is ";
echo $c1->class2->ref_to_class1->foo, "\n<hr>"; /* fails !!!! */
/* it doesn't matter if one accesses ref_to_class1 through $c1 or $c2, it hasn't
a valid type any more */
if(isset($c2->ref_to_class1))
echo "isset(\$c2->ref_to_class1) is TURE\n";
else echo "isset(\$c2->ref_to_class1) is FALSE\n";
/* ref_to_class1 is set, but of unknown type */
echo "gettype(\$c2->ref_to_class1): ", gettype($c2->ref_to_class1), "\n";