php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2467 Corrupted data structures
Submitted: 1999-10-08 09:47 UTC Modified: 1999-10-09 15:30 UTC
From: alan at sanguis dot com dot au Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Latest CVS (08/10/1999) OS: RH6.0 + DSO Apache-1.3.9
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alan at sanguis dot com dot au
New email:
PHP Version: OS:

 

 [1999-10-08 09:47 UTC] alan at sanguis dot com dot au
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();

?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-10-09 15:30 UTC] andi at cvs dot php dot net
Hopefully this is fixed in the CVS. Please update libzend and do a make clean before you recompile. Let us know what happens.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 04:01:38 2024 UTC