php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6354 A property making trouble
Submitted: 2000-08-25 11:26 UTC Modified: 2000-09-21 10:30 UTC
From: k dot reimer at twisd dot de Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.1pl2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: k dot reimer at twisd dot de
New email:
PHP Version: OS:

 

 [2000-08-25 11:26 UTC] k dot reimer at twisd dot 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-31 09:12 UTC] 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-31 09:13 UTC] stas@php.net
and recalssify it...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 10:01:32 2024 UTC