PHP 4.0 Bug #6354 Updated: A property making trouble
| From: | Bug Database | Date: | Thu, 21 Sep 2000 14:30:48 +0000 |
| Subject: | PHP 4.0 Bug #6354 Updated: A property making trouble | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-33467@lists.php.net to get a copy of this message | ||
ID: 6354
Updated by: sniper
Reported By: k.reimer@twisd.de
Status: Closed
Bug Type: Scripting Engine problem
Assigned To:
Comments:
Previous Comments:
---------------------------------------------------------------------------
[2000-08-31 09:12:36] stas@php.net
1. You should never use foo(&$var). Please read the "References explained" part in the
manual and see how to call by-reference.
2. Could you please check that the problem still is there in 4.0.2?
3. If so, could you please cut down your script as much as possible while it still reproduces the
buggy behaviour?
---------------------------------------------------------------------------
[2000-08-25 11:26:48] k.reimer@twisd.de
Well, I think this has something to do with bug #6352 I have posted today. A very strange behaviour.
Here is the source:
<?php
class CBase {
var $aChildren=array();
function CBase($hParent=0) {
if ($hParent!=0) $hParent->addChildren(&$this);
}
function addChildren($Children) {
$this->aChildren[]=&$Children;
}
function draw() {
$this->drawChildren();
}
function drawChildren() {
for ($iCount=0;$iCount<count($this->aChildren);$iCount++)
$this->aChildren[$iCount]->draw();
}
function printMe($sValue) {
printf($sValue);
}
}
class CBaseExt extends CBase {
var $sBugMaker;
function draw() {
$this->printMe($this->sBugMaker);
$this->drawChildren();
}
}
class CChild extends CBase {
function draw() {
printf("It's working!<br>n");
}
}
class CParent extends CBaseExt {
function CParent($Parent=0) {
// Comment me out, and I will work...
$this->sBugMaker="I'm the trouble maker";
$this->Table=new CChild(&$this);
}
}
$Page=new CParent();
$Page->draw();
?>
This script creates the class Parent. The constructor of the Parent creates
a child. If I draw the Parent, the Child is drawn, too.
This code produces the follwoing error:
Fatal error: Call to a member function on a non-object in /var/www/ailis.de/bugs/bug.php on line 20
Looks like I have an error in my script, but... If I comment out the line where I write something in
the Property $sTroubleMaker, the script is working.
I can't imagine that this is an error in my script. This line seems to be
messing around ALOT, if I extend the script to do a lot of normal tasks
with classes, it produces Segfaults. And again, if I remove the line, all
is working perfectly.
You can test this behaviour. I have published this script with and without error here:
http://www.ailis.de/bugs/bug.php
http://www.ailis.de/bugs/nobug.php
bug.txt und nobug.txt are symbolic links to these files, so you can read
the source code.
I have reproduced this bug on three different machines. All are running
apache 1.3.9 and php 4.01pl2 under linux.
Maybe you can reproduce another strange behaviour: Load the nobug.php-Link from above in to a
browser. The script is working. Now hit reload and it maybe that you get the same error message if
loading bug.php. I can reproduce this with Netscape, but not with Konqueror. Really strange.
Bye
K
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=6354