-
Notifications
You must be signed in to change notification settings - Fork 667
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
TypeDoesNotContainNull: on return value from dom_import_simplexml() #6151
Comments
I found these snippets: https://psalm.dev/r/42bcd39f32<?php
class Foo {
public function test(\SimpleXMLElement $xmlElement): \SimpleXMLElement
{
$domElement = dom_import_simplexml($xmlElement);
if (null === $domElement) {
throw new \LogicException('Error');
}
return $domElement;
}
}
|
I'm not sure about that - can you devise a reproducer showing |
Not entirely sure how i can make a reproducer. But going through the source code i did notice that going from 7.4 to 8.0 the return has been changed. |
But from what i can see, the function can now only return a DOMElement. And it will throw a ValueError on failure. (ArgumentCountError when not enough arguments are supplied) |
Indeed, the function doesn't seem to have ever returned false. The return null was kinda legit before 8.0 but was only returned when wrong params were send. Psalm already reports wrong params so adding the null return type would be redundant. So, all that is needed is to remove false from the type in the callmaps. We actually have a doc page if you want to contribute on that: https://psalm.dev/docs/contributing/editing_callmaps/ Care for a PR? :) |
PR is open |
…otcontainnull-on-return-value-from-dom_import_simplexml Bugfix/#6151 typedoesnotcontainnull on return value from dom import simplexml
When using the
dom_import_simplexml()
function, psalm gives aTypeDoesNotContainNull
warning when performing a null check on the return value. Psalm still indicates the return type to beDOMElement|false
while the actual return type isDOMElement|null
.Example: https://psalm.dev/r/42bcd39f32
The text was updated successfully, but these errors were encountered: