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 will need a quick solution the reason
why I write this to the list instead of to bugs.php.net.
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:
-----------------
<?
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);
?>
---------
Output expected:
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 Output:
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
}
}
-------
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
--
mike peter bretz metropolis ag / entwicklung
email: [EMAIL PROTECTED] heinestraße 72
phone: +49-7121-348-120 d-72762 reutlingen
fax: +49-7121-348-111 http://www.metropolis-ag.de/
metropolis ag. creating social internetworks.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php