-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SimpleXMLElement - SimpleXMLIterator::var is not defined - After property_exists check #6686
Comments
Reproduced: https://psalm.dev/r/ac48378869 |
I found these snippets: https://psalm.dev/r/ac48378869<?php
$xml = <<<XML
<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
XML;
$xmlObject = simplexml_load_string($xml);
if ($xmlObject instanceof SimpleXMLElement) {
$projectFiles = $xmlObject->children('projectFiles', true);
if (property_exists($projectFiles, 'projectFiles')) {
if ($projectFiles->projectFiles instanceof SimpleXMLElement) {
return true;
}
}
}
|
You can add <universalObjectCrates>
<class name="SimpleXMLIterator"/>
</universalObjectCrates> in your config file to resolve this (Psalm will consider any property as existing). It should probably be something more integrated in Psalm though so I'll let this issue open |
You can also use |
I found these snippets: https://psalm.dev/r/4ef9699b4f<?php
$xml = <<<XML
<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
XML;
$xmlObject = simplexml_load_string($xml);
if ($xmlObject instanceof SimpleXMLElement) {
$projectFiles = $xmlObject->children('projectFiles', true);
if (isset($projectFiles->projectFiles)) {
if ($projectFiles->projectFiles instanceof SimpleXMLElement) {
return true;
}
}
}
|
Thanks @weirdan |
It should. |
The case for SimpleXMLIterator is fixed by PR above. The case for property_exists is a duplicate of #4182 |
With the following, I get a
Instance property SimpleXMLIterator::$projectFiles is not defined (see https://psalm.dev/039)
Now, I already check that
$projectFiles
is a property, with myproperty_exists
methodIsnt this a false positive call, or is there a way to get rid of that check?
The text was updated successfully, but these errors were encountered: