PHP 4.0 Bug #6352: Crash while using references and classes

From: Date: Fri, 25 Aug 2000 13:14:28 +0000
Subject: PHP 4.0 Bug #6352: Crash while using references and classes
Groups: php.dev 
Request: Send a blank email to php-dev+get-30636@lists.php.net to get a copy of this message
From: k.reimer@twisd.de Operating system: Debian Potato (Kernel 2.2) PHP version: 4.0.1pl2 PHP Bug Type: Reproduceable crash Bug description: Crash while using references and classes Below is a medium source code file where I can reproduce one strange behaviour and one segfault-crash. Below the source you find a short description what this script does (or not): <?php // --- Base class --- class CBase { var $aChildren=array(); function CBase($Parent=0) { if ($Parent!=0) $Parent->addChildren(&$this); } function addChildren($Children) { $this->aChildren[]=&$Children; } function drawChildren() { while ($a=each($this->aChildren)) $a[value]->draw(); } } // --- Test class 1 --- class CTest extends CBase { function CTest($Parent=0) { // --- Block 1 begin------------ // global $Test2; // $Test2=new CTest2(&$this); // --- Block 1 end ------------- // --- Block 2 begin ----------- // $this->Test2=new CTest2(&$this); // --- Block 2 end ------------- } function draw() { printf("This is CTest<br>\n"); $this->drawChildren(); } } // --- Test class 2 --- class CTest2 extends CBase { function draw() { printf("This is CTest2<br>\n"); } } printf("<html><body>"); $Test=new CTest(); // --- Block 3 begin ------ $Test2=new CTest2(&$Test); // --- Block 3 end -------- // --- Block 4 begin ------ // $Test->Test2=new CTest2(&$Test); // --- Block 4 end -------- $Test->draw(); printf("</body></html>"); ?> This script defines one base class providing a parent-children-draw-concept. Another two classes are derived from this class. I want to make $Test2 a children of $Test. If I call the draw()-method of $Test the draw()-methods of the children are called automatically. I have commented four blocks in this script. If you use block 3, all is working fine. A reference to $Test is given as parameter to the constructor of $Test2. If you use block 2 the same is done by using the reference on $this. But this is not working and I don't know why. I thought it is not working because block 2 is creating $Test2 as a property of $Test, but if you use block 4, it is working fine. And now to block 1. There I define $Test2 as global and do the same as before. This time php is crashing with a segmentation fault. Please inform me if this is really a bug and how fast you can repair it, because I need this feature. Bye K

« previous php.dev (#30636) next »