ID:               36647
 Updated by:       [EMAIL PROTECTED]
 Reported By:      pumuckel at metropolis dot de
-Status:           Open
+Status:           Feedback
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      5CVS-2006-03-07 (snap)
 New Comment:

Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2006-03-07 17:41:46] pumuckel at metropolis dot de

Description:
------------
Hello,

we currently monitor segmentation faults on all of our production and
development servers running php 5.0.5 and 5.1.2 which leads to a
complete application failure. 

We traced down the problem to be associated with a foreach loop over an
array return by __get method within a class.

The segmentation fault occurs randomly either while shutting down php
module (while cleaning up memory) or just within the application after
the foreach loop.

Using the current snapshot the problem can be reproduced visually
(without segfaults) as follows: See Reproduce code

I think the foreach within the X function in conjunction with the $bar
variable is freeing $t->errors array, which in fact is wrong behaviour.
Using $bar var as input for the foreach makes the application working,
too.

Note that this small application does not segfault, but when executing
some (a lot) just before and after that code sniplet it almost always
leads to a crash here.

Who is able to look at that and provide a patch?

Thank you,

 Mike 

Reproduce code:
---------------
<?
 class Foo {
   private $data = array("errors" => array(1, 2, 3));
   function __get($x) {
     return $this->data[$x];
   }
 }

 $t = new Foo();
 var_dump($t);

 function X(Foo $t) { // when using the foreach within a function the
error gets triggered
   // following 2 lines have to be enabled to see the bug.
   $bar = $t->errors;  // not using this line makes the script
working.
   foreach($t->errors as $foo);  // not using this line also makes the
script working.
 }

 X($t);
 var_dump($t);
?>

Expected result:
----------------
object(Foo)#4 (1) {
 ["data:private"]=>
 array(1) {
   ["errors"]=>
   array(3) {
     [0]=>
     int(1)
     [1]=>
     int(2)
     [2]=>
     int(3)
   }
 }
}
object(Foo)#4 (1) {
 ["data:private"]=>
 array(1) {
   ["errors"]=>
   array(3) {
     [0]=>
     int(1)
     [1]=>
     int(2)
     [2]=>
     int(3)
   }
 }
}


Actual result:
--------------
object(Foo)#4 (1) {
 ["data:private"]=>
 array(1) {
   ["errors"]=>
   array(3) {
     [0]=>
     int(1)
     [1]=>
     int(2)
     [2]=>
     int(3)
   }
 }
}
object(Foo)#4 (1) {
 ["data:private"]=>
 array(1) {
   ["errors"]=>
   NULL
 }
}



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=36647&edit=1

Reply via email to