php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23038 PHP does not detect parent class inside child class' constructor
Submitted: 2003-04-03 11:42 UTC Modified: 2003-09-08 08:58 UTC
Votes:5
Avg. Score:4.0 ± 1.5
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:1 (20.0%)
From: black at sunshine dot krneki dot org Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4.3.3RC2-dev OS: linux debian
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-04-03 11:42 UTC] black at sunshine dot krneki dot org
On bugreport 21478 i've experienced the same problem and behaviour 
when trying to debug, but i believe the bugs are generally unrelated. 
 
I've been searching to the sollution for my segfaulting of apache in 
various areas... output buffering, stream functions (file access, 
file_get_contents), references... and since i got the crashes in 4.3 then 
i thought of the only thing i added to the code which was 4.3 related, 
and that was the use of aggregate.. 
 
i used aggregate to aggregate 3-4 classes to a main object, and after 
removing and reforming the classes to preform a row of "extends" on 
them.. the behaviour wen't away, and I didnt get a single segfault in 
the last 3-4 days. 
 
it is my opinion that aggregate either contains a memory leak 
somewhere, or that the problem is located inside the scripting engine.. 
 
i dont have anything to reproduce it anymore, except old cvs 
snapshots which could reproduce it if required, but removing aggregate 
and with it the segfaults seems to be enough of an indication for me. 
 
this seems to be related to 4.3.0 and later, and was reproduced on my 
side on every php version up to 4.5-CVS 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-03 12:24 UTC] sniper@php.net
I'm tempted to bogusify this right away since you only 
assume a lot here. Please provide real information we can
work with..like a simple example script.

(and FYI: there is no such thing as 4.5-dev officially)

 [2003-04-03 15:38 UTC] black@php.net
according to http://snaps.php.net there is? 
 
and yeah, i guess you could mark it as bogus, as far as "simple" 
scripts go, i doubt i could ever reproduce this in a simple one.. even 
the collection of code i use has about 170k just core files (and its 
clean non bloated code if you believe it ;)).. 
 
the best i can do is give you a cvs snapshot of a week ago when the 
bug was still occuring.. after i removed aggregate i havent had a 
crash.. 
 
as for my debugging knowledge goes, its pretty much what i gathered 
from this page, and you cant really expect me to master gdb and 
valgrind without experience with any of them before. 
 
if you want to give it a shot then by all means, im willing to give you 
everything that is in my power to do so, a short example script 
however, is not. 
 [2003-04-06 16:22 UTC] black@php.net
just letting you know that its been a week now with not a single crash 
after removing aggregate - contact me when/if you want/need the db 
dump and code dump to analyze this/test it. 
 [2003-05-23 11:14 UTC] hewei at ied dot org dot cn
This short script can reproduce the aggregation bug I reported above.

class bar {
 
   function doit()
   {
      print " Doing...\n";
   }
}


class foo {

   function foo()
   {
       print_r(aggregation_info($this));
       aggregate($this, "bar");
   }
   
   function spawn()
   {
       return new foo();
   }
}

$a = new foo();
$a->doit();
$b = $a->spawn();
$b->doit();
unset($a);
$c = $b->spawn();
$c->doit();

Besides 'unset($a)', '$a = new foo()' will also cause the same problem.
 [2003-06-04 14:02 UTC] andrei@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2003-06-21 09:17 UTC] hewei at ied dot org dot cn
The bug is not fixed. Run the following script either before or after applying andrei's recent patch, one will reproduct the bug.
<?php

class bar {
 
   function doit()
   {
      print "Doing bar as " . get_class($this) . " ...\n";
   }
}

class foo {

   function foo()
   {
       print_r(aggregation_info($this));
       aggregate($this, "bar");
   }
}

class foobar extends foo {
}

$a = new foo();
$a->doit();

unset($a);

$b = new foobar();
$b->doit();

?>
 [2003-07-27 14:30 UTC] iliaa@php.net
This problem has little to do with aggregation functions. This is a ZE scripting language problem. This can be demonstrated by adding var_dump(get_class($this)) inside the foo constructor. It'll always print "foo", the name of the class for the class the constructor is for, not the 'real' class.
 [2003-08-05 21:57 UTC] hewei at ied dot org dot cn
The following message is what I send to PHP's developer list on Jun 18. It was never confirmed by anyone for whether my analysis was correct or not. 

My conclusion could be very possibily wrong as my understanding to PHP/Zend sources was still very shallow.
I just hope it may provide useful information for anyone on further studying of this bug.

I still hope Andrei or someone else that knows something can confirm this. I spent quite sometime trying to find out if I can do something on this bug as my contribution of PHP.
----------------------------------------------------------

According to my deeper analysis. Unsetting an object will not touch any thing related to the object execpt remove it from the active symbol table. And the same memory location(or handle) will be reallocated to the next new object in some circumstances.

If so, aggregate.c will have a problem as it keeps an external hash on the objects' handle and their aggregation information. Then when an object is unset, there is no way to inform aggregate.c (or any other extensions doing the similar thing) to remove the corresponding item from it's hash. And the next new object happened to use the same memory location will still be regarded as the original one by aggregate.c. That's why the above script will print a wong class name. Also because the old object was aggregated, the aggregate.c will refuse to perform aggregation on it.

So I guess it is not easy to fix the bug unless a patch is made to Zend codes to add a hook for aggregate.c to deaggregate an object when unsetting (or maybe in some other places, like assigning it with a same object).
 [2003-09-03 05:32 UTC] hewei at ied dot org dot cn
Although the ChangeLog says that this bug has been fixed,
my above script still doesn't work as expected.
 [2003-09-08 08:58 UTC] sniper@php.net
aggregate does not exist in PHP 5. And as we're focusing on PHP 5 development, this is now 'wont fix' for PHP 4.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 11:01:28 2024 UTC