Skip to content
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

Dynamic properties of SimpleXMLElement should be inferred as being SimpleXMLElement #9997

Closed
stof opened this issue Jul 5, 2023 · 2 comments

Comments

@stof
Copy link
Contributor

stof commented Jul 5, 2023

https://psalm.dev/r/100575e0f4

This reports mixed errors saying it cannot infer the type of expressions. But dynamic properties of SimpleXMLElement are always SimpleXMLElement themselves.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/100575e0f4
<?php

$string = <<<XML
<a>
 <foo name="one" game="lonely">1</foo>
</a>
XML;

$xml = new SimpleXMLElement($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
    echo $a,'="',$b,"\"\n";
}
Psalm output (using commit 8fe1f15):

INFO: MixedArrayAccess - 10:9 - Cannot access array value on mixed variable $xml->foo

INFO: MixedMethodCall - 10:23 - Cannot determine the type of $xml->foo[0] when calling method attributes

INFO: MixedAssignment - 10:39 - Unable to determine the type that $a is being assigned to

INFO: MixedAssignment - 10:45 - Unable to determine the type that $b is being assigned to

INFO: MixedArgument - 11:10 - Argument 1 of echo cannot be mixed, expecting string

INFO: MixedArgument - 11:18 - Argument 3 of echo cannot be mixed, expecting string

@stof
Copy link
Contributor Author

stof commented Jul 5, 2023

Based on the discussion in phpstan/phpstan#9575, it should be inferred as SimpleXMLElement|null

@stof stof changed the title Dynamic properties of SimpleXMLElement should be infered as being SimpleXMLElement Dynamic properties of SimpleXMLElement should be inferred as being SimpleXMLElement Jul 5, 2023
ygottschalk added a commit to ygottschalk/psalm that referenced this issue Jul 25, 2023
- make SimpleXmlElement and SimpleXmlIterator not a universal object crate
- added typed magic __get method to SimpleXmlElement
- 'fixed' code translating `null` to `TNamedObject('null')` instead of `TNull`
ygottschalk added a commit to ygottschalk/psalm that referenced this issue Jul 25, 2023
- make SimpleXmlElement and SimpleXmlIterator not a universal object crate
- added typed magic __get method to SimpleXmlElement
- 'fixed' code translating `null` to `TNamedObject('null')` instead of `TNull`
ygottschalk added a commit to ygottschalk/psalm that referenced this issue Jul 25, 2023
- make SimpleXmlElement and SimpleXmlIterator not a universal object crate
- added typed magic __get method to SimpleXmlElement
- adjusted tests to reflect new behaviour of SimpleXmlElement
- added tests
- 'fixed' code translating `null` to `TNamedObject('null')` instead of `TNull`
ygottschalk added a commit to ygottschalk/psalm that referenced this issue Jul 25, 2023
- make SimpleXmlElement and SimpleXmlIterator not a universal object crate
- added typed magic __get method to SimpleXmlElement
- adjusted tests to reflect new behaviour of SimpleXmlElement
- added tests
- 'fixed' code translating `null` to `TNamedObject('null')` instead of `TNull`
ygottschalk added a commit to ygottschalk/psalm that referenced this issue Aug 5, 2023
- make SimpleXmlElement and SimpleXmlIterator not a universal object crate
- added typed magic __get method to SimpleXmlElement
- adjusted tests to reflect new behaviour of SimpleXmlElement
- added tests
ygottschalk added a commit to ygottschalk/psalm that referenced this issue Aug 5, 2023
- make SimpleXmlElement and SimpleXmlIterator not a universal object crate
- added typed magic __get method to SimpleXmlElement
- adjusted tests to reflect new behaviour of SimpleXmlElement
- added tests
@orklah orklah closed this as completed in a4de6d9 Aug 5, 2023
orklah added a commit that referenced this issue Aug 5, 2023
…dynamic-properties

Fix #9997 dynamic properties on SimpleXmlElement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant