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?
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.