Edit report at http://bugs.php.net/bug.php?id=53973&edit=1
ID: 53973 Updated by: [email protected] Reported by: equinox at lichtspiele dot org Summary: storing SimpleXMLObject to class property does not always work (is null) -Status: Open +Status: Feedback Type: Bug Package: Class/Object related Operating System: debian squeeze/sid PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: Please supply a working script to reproduce this; the current have several faults: - There is no such class as SimpleXMLObject, simplexml uses SimpleXMLElement - The prototype for ProjectXML::foo() is not valid, typehinting should not use ( + ) around the hint - ProjectXML::foo() uses $xml_node, and the argument is named $xml - ProjectXML::foo() is called without the $search_criteria, producing a warning Previous Comments: ------------------------------------------------------------------------ [2011-02-09 16:13:07] equinox at lichtspiele dot org Description: ------------ The PHP-Version is 5.3.3-7 (was not able to select this version in the dropdown box) When storing a SimpleXMLObject to a class property the property is null sometimes (every 3rd - 5th call). According to this error, PHP seems to loose all object descriptors ($this) in *all* classes, which leads to misleading error messages like "trying to get property of non-object in ..", even if I checked $this to be an object 1 line before the error message happens (How can $this be not an object? I am always in object context). Current solution: When casting the SimpleXMLObject to an Array and storing it to the class property both problems do not appear. Test script: --------------- class ProjectXML { private $project_xml; public function foo((SimpleXMLObject) $xml, $search_criteria) { // search a specific node, save it to the class property and return true $this->project_xml = $xml_node; return true; } public function bar() { var_dump($this->project_xml); } } $class = new ProjectXML(); $class->foo(simplexml_load_file("/path/to/project.xml")); $class->bar(); /* The used code is very complex, so I reduced it to a minimum. The full code can be viewed here: http://quantum-framework.org/ProjectXML.class.phps */ Expected result: ---------------- SimpleXMLObject Actual result: -------------- sometimes null sometimes the SimpleXMLObject ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53973&edit=1
