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

SimpleXMLElement types are wrong #9575

Open
stof opened this issue Jul 5, 2023 · 3 comments
Open

SimpleXMLElement types are wrong #9575

stof opened this issue Jul 5, 2023 · 3 comments
Labels
Milestone

Comments

@stof
Copy link
Contributor

stof commented Jul 5, 2023

Bug report

Dynamic properties on SimpleXMLElement don't ever return null. Even for a non-existent child, it still returns a SimpleXMLElement (with a count of 0). See https://3v4l.org/a6OFI for the proof.

Array access on SimpleXMLElement also returns SimpleXMLElement objects, not mixed

Code snippet that reproduces the problem

https://phpstan.org/r/5940e7c0-7917-48e8-b4d2-b218480877dc

Expected output

SimpleXMLElement types instead of nullable or mixed types.

Did PHPStan help you today? Did it make you happy in any way?

No response

@ondrejmirtes
Copy link
Member

The null part was added based on: #2784

@stof
Copy link
Contributor Author

stof commented Jul 5, 2023

OK, SimpleXMLElement is even more weird than what I thought.

So maybe the only remaining thing to fix is the better type for the array access.

@phpstan-bot
Copy link
Contributor

@stof After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
 14: Dumped type: (SimpleXMLElement|null)
 15: Dumped type: mixed
 16: Dumped type: (SimpleXMLElement|null)
-17: Dumped type: SimpleXMLElement|null
+17: Dumped type: (SimpleXMLElement|null)
Full report
Line Error
14 `Dumped type: (SimpleXMLElement
15 Dumped type: mixed
16 `Dumped type: (SimpleXMLElement
17 `Dumped type: (SimpleXMLElement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants