From: [EMAIL PROTECTED]
Operating system: RedHat 7.1
PHP version: 4.1.1
PHP Bug Type: Reproducible crash
Bug description: array_reduce() causes segmentation faults
This drove me crazy. array_reduce() causes segmentation faults when used in
a complex, recursive manner. I'm pretty sure it's array_reduce() and not
create_function() that's the culprit here. I'm sorry I can't provide a
simpler example, but I've been unable to reprodce the crash otherwise. I'll
try to describe what I'm doing to the best of my abilities.
debug.php is an include that I use for dumping out nicely-formatted data
structures - it works like print_r() but cleaner. It's written using
functional techniques, so I'm using create_function() as a lambda and
array_reduce() as a reduction.
tree.xml is an XML file that I'm parsing into a data structure using
wddx_deserialize(). I thought that it was my deserialization that was the
problem when I was using XML-RPC, and switched to WDDX in hopes that that
would solve the crash problem. It didn't. It took a lot of monkeying around
before I figured out where the real problem was.
I don't know how to use GDB, and I don't really have any more time to
dedicate to this, so no backtrace. Sorry. I've experienced this problem
with PHP 4.1.0, 4.1.1, and 4.2.0-dev under RedHat 7.1 and Apache 1.3.22.
Here are my source files:
crash.php (this is the one to run)
<pre>
<?php
require_once 'debug.php';
$data = wddx_deserialize(join('', file('tree.xml')));
// This works.
print_r($data);
// This doesn't.
//debug($data);
?>
</pre>
debug.php:
<?php
function array_items($array) {
$result = array();
foreach ($array as $key => $val) $result[] = array($key, $val);
return $result;
}
function debug_node($key, $val) {
return "-+ <font color=\"#ad0000\"><b>$key</b></font> "
. "<font color=\"#505050\">(" . gettype($val) .
")</font><br>\n";
}
function debug_leaf($key, $val) {
return "-> <b>$key</b> = <font color=\"#0000ad\">$val</font> "
. "<font color=\"#505050\">(" . gettype($val) .
")</font><br>\n";
}
function debug_reduce($prep, $accum, $key_val) {
list($key, $val) = $key_val;
return "$accum$prep" . (is_array($val) ? debug_node($key, $val)
. debug_tree("$prep |", $val)
: debug_leaf($key,
$val));
}
function debug_tree($prep, $array) {
return array_reduce(array_items($array),
create_function('$a, $x',
"return debug_reduce('$prep', \$a, \$x);"),
'');
}
function debug_array($array) {
return "<font face=\"arial\" size=3 color=\"black\"><code>\n"
. debug_tree('|', $array) . '</code></font>';
}
function debug_string($string) {
return "<font face=\"arial\" size=2 color=\"black\">\n"
. nl2br($string) . "</font>\n";
}
function debug($msg) {
?>
<table width="100%" border=0 cellpadding=5 cellspacing=0 bgcolor="#dedede"
bordercolor="black"><td>
<?=(is_array($msg) or is_object($msg)) ? debug_array($msg) :
debug_string($msg)?>
</td></table>
<table width="100%" height=1 cellpadding=0 cellspacing=0
bgcolor="black"><td></td></table>
<?
return $msg;
}
?>
tree.xml:
<?xml version="1.0"?><!DOCTYPE wddxPacket SYSTEM
"../static/wddx_0090.dtd"><wddxPacket version="0.9"><header/><data><array
length="
4"><struct><var name="label"><string>About Us</string></var><var
name="children"><array length="2"><struct><var name="label"><strin
g>Who We Are</string></var><var name="children"><array
length="0"></array></var><var
name="path"><string>about/who</string></var><v
ar name="content"><array
length="2"><number>23</number><number>42</number></array></var></struct><struct><var
name="label"><string>
What We Doodoo</string></var><var name="children"><array
length="0"></array></var><var
name="path"><string>about/what</string></var
><var name="content"><array
length="1"><number>69</number></array></var></struct></array></var><var
name="path"><string>about</stri
ng></var><var name="content"><array
length="0"></array></var></struct><struct><var
name="label"><string>Products</string></var><var
name="children"><array length="0"></array></var><var
name="path"><string>products</string></var><var name="content"><array
length=
"2"><number>86</number><number>99</number></array></var></struct><struct><var
name="label"><string>Services</string></var><var name
="children"><array length="0"></array></var><var
name="path"><string>services</string></var><var name="content"><array
length="0"><
/array></var></struct><struct><var name="label"><string>Contact
Us</string></var><var name="children"><array length="0"></array></v
ar><var name="path"><string>contact</string></var><var
name="content"><array
length="1"><number>1</number></array></var></struct></
array></data></wddxPacket>
That's it. Good luck.
Peace,
Dave
--
Edit bug report at: http://bugs.php.net/?id=14749&edit=1
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]