0

All,

I'm using PHPLint to evaluate a PHP script I'm writing, and it returns the following error:

"ERROR: property `SimpleXMLElement::$error' does not exist or not visible".

The code referred to looks like this:

$this->_xmlResponse = new SimpleXMLElement($resultString);

if (($this->_xmlResponse !== NULL) && ($this->_xmlResponse->error))

And _xmlResponse is a class variable declared like this:

private /*. SimpleXMLElement .*/ $_xmlResponse = NULL;

The way the SimpleXMLElement class works is you refer to an XML element by name using the -> operator. So I'm referring to the "error" element from my SimpleXMLElement object.

I am also getting errors like this one:

ERROR: `->' operator applied to a value of type mixed

When accessing elements like this:

print ' by ' . htmlentities($status->user->screen_name) . '</h6>';

The code works fine, but PHPLint still gives the errors. I've looked through the PHPLint reference manual but I can't figure out if PHPLint is unable to parse SimpleXMLElement, or if this is really something that is a potential problem. Can anyone explain this PHPLint error? Perhaps there is some type casting I need to do?

hakre
  • 193,403
  • 52
  • 435
  • 836
North Krimsly
  • 879
  • 4
  • 18
  • 33

1 Answers1

0

You've brought up two separate issues. First, SimpleXMLElement (as of PHP 5.3.6) has no error attribute. See the documentation here. If you read the constructor documentation you'll see the correct way to detect an error is to catch an exception thrown by the constructor. The second error is most likely do to $status (or $status->user) having a @mixed PHPDocumentor annotation on it, which is used by PHPLint. Changing the annotation to @object should address your issue.

Blake Mathman
  • 2,699
  • 1
  • 23
  • 20
  • bmatheny, `$this->_xmlResponse->error` means "grab me the XML element in the SimpleXMLElement object, named "error". SimpleXMLElement contains parsed XML which you can access by the name of each XML element. "error" is the name of a valid XML element which does exist in the SimpleXMLElement object instance, from my parsed XML. The code works fine, but PHPLint complains about it. The "not visible" error I'm getting is produced by PHPLint, it is not produced by the code in the SimpleXMLElement object class. – North Krimsly Jun 16 '11 at 17:44
  • Understood. The second comment is still relevant. PHPLint in the first case is using the reflection class to determine if that attribute exists and it thinks it doesn't (which is true in a static context). I still think the second issue is annotation based but it may be a symptom of the same kind of issue (reflection shows no such member). – Blake Mathman Jun 16 '11 at 17:48