php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53973 storing SimpleXMLObject to class property does not always work (is null)
Submitted: 2011-02-09 16:13 UTC Modified: 2013-02-18 00:34 UTC
From: equinox at lichtspiele dot org Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.3.5 OS: debian squeeze/sid
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: equinox at lichtspiele dot org
New email:
PHP Version: OS:

 

 [2011-02-09 16:13 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-12 09:45 UTC] kalle@php.net
-Status: Open +Status: Feedback
 [2011-02-12 09:45 UTC] kalle@php.net
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
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 17:01:28 2024 UTC