php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6352 Crash while using references and classes
Submitted: 2000-08-25 09:14 UTC Modified: 2000-08-25 16:23 UTC
From: k dot reimer at twisd dot de Assigned:
Status: Closed Package: Reproducible Crash
PHP Version: 4.0.1pl2 OS: Debian Potato (Kernel 2.2)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
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 09:14 UTC] k dot reimer at twisd dot de
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-25 16:23 UTC] waldschrott@php.net
Pass-by-reference from call-time is deprecated and optional
referenced parameters are not implemented, I?ve modified
your script, thus you should be able to figure out, how to
do this in PHP4....


<?php

  // --- Base class ---

  class CBase {
    var $aChildren=array();

    function addChildren(&$Children) {
      $this->aChildren[]=&$Children;
    }

    function drawChildren() {	
      while ($a=each($this->aChildren)) {

		$a[value]->draw(); }
    }
  }

  // --- Test class 1 ---

  class CTest extends CBase {

    function draw() {
      printf("This is CTest<br>\n");  }
  }

  // --- Test class 2 ---

  class CTest2 extends CBase {
    function draw() {
      printf("This is CTest2<br>\n");
	        $this->drawChildren();
    }
  }

  printf("<html><body>");
  $Test=new CTest();

  // --- Block 3 begin ------
  $Test2=new CTest2();
  $Test2->addChildren($Test);

  $Test2->draw();
  printf("</body></html>");
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 23:01:27 2024 UTC