PHP 4.0 Bug #2467: Corrupted data structures
| From: | alan at sanguis dot com dot au | Date: | Fri, 08 Oct 1999 13:47:16 +0000 |
| Subject: | PHP 4.0 Bug #2467: Corrupted data structures | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-11628@lists.php.net to get a copy of this message | ||
From: alan@sanguis.com.au
Operating system: RH6.0 + DSO Apache-1.3.9
PHP version: 4.0 Latest CVS (08/10/1999)
PHP Bug Type: Scripting Engine problem
Bug description: Corrupted data structures
The object hierachy produced by the following code is corrupted for some reason that I have not been
able to determine. If the class variable 'properties' is manipulated directly ther is no
problem, however if the helper function 'prop()' is used the data structure is corrupted
in that the contents of the 'properties' array are changed.
I have been able to determine roughly when this problem arose (through checking out cvs for various
days.). It seems to have popped up around the 30th of october.
<?php
class part{
function part($args=""){
$this->properties=array();
reset($args);
while($cur=each($args)){
$this->prop($cur['key'],$cur['value']);
}
}
function prop($var,$arg){
if (!isset($arg)){
// single argument, return current value
return $this->properties[$var];
}
// set and return new value
return $this->properties[$var]=$arg;
}
function show($indent=""){
echo "${indent}Properties of ".$this->prop("name").":\n";
$indent.="\t";
reset($this->properties);
while($cur=each($this->properties)){
//ignore index 'obj'
if ($cur['key']!="obj")echo "${indent}${cur['key']} =
${cur['value']} \n";
}
}
}
class assembly extends part{
function assembly($args="",$parts=""){
// call base constructor
$this->part($args);
$this->properties['obj']=array();
// add parts
$this->add($parts);
}
function add(&$parts){
reset($parts);
while($cur=each($parts)){
if (is_object($cur['value'])){
//
// uncomment only one of the following '$name=...' lines.
//
// this method of setting $name works
// $name=$cur['value']->properties["name"];
//
// this method of setting $name kills the contents of $this->properties...
$name=$cur['value']->prop("name");
//
$this->properties['obj'][$name]=$cur['value'];
}
}
}
function show($indent=""){
// list properties first
part::show($indent);
if (!is_array($this->properties['obj'])) return;
// list member objects
echo "${indent}member count is
".sizeof($this->properties['obj'])."\n";
echo "${indent}Members of ".$this->prop("name").":\n";
$indent.="\t";
reset($this->properties['obj']);
while($cur=each($this->properties['obj'])){
if (is_object($cur['value'])){
$cur['value']->show($indent);
}
else{
echo "\nshould be an object, value is
'".$cur['value']."'\n";
}
}
}
}
$door=new assembly(
array(
"name"=>"door",
"colour"=>"green"
),
array(
new part(
array(
"name"=>"panel",
"material"=>"wood"
)
),
new assembly(
array(
"name"=>"handle",
"type"=>"round"
),
array(
new part(
array(
"name"=>"inside knob"
)
),
new part(
array(
"name"=>"outside knob"
)
)
)
)
)
);
$door->show();
?>