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

Bugfix/#6151 typedoesnotcontainnull on return value from dom import simplexml #7489

Merged
merged 3 commits into from Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dictionaries/CallMap.php
Expand Up @@ -2051,7 +2051,7 @@
'dom_document_schema_validate' => ['bool', 'source'=>'string', 'flags'=>'int'],
'dom_document_schema_validate_file' => ['bool', 'filename'=>'string', 'flags'=>'int'],
'dom_document_xinclude' => ['int', 'options'=>'int'],
'dom_import_simplexml' => ['DOMElement|false', 'node'=>'SimpleXMLElement'],
'dom_import_simplexml' => ['DOMElement', 'node'=>'SimpleXMLElement'],
'dom_xpath_evaluate' => ['', 'expr'=>'string', 'context'=>'DOMNode', 'registernodens'=>'bool'],
'dom_xpath_query' => ['DOMNodeList', 'expr'=>'string', 'context'=>'DOMNode', 'registernodens'=>'bool'],
'dom_xpath_register_ns' => ['bool', 'prefix'=>'string', 'uri'=>'string'],
Expand Down
4 changes: 4 additions & 0 deletions dictionaries/CallMap_80_delta.php
Expand Up @@ -309,6 +309,10 @@
'old' => ['string|false', 'object'=>'DateTimeInterface', 'format'=>'string'],
'new' => ['string', 'object'=>'DateTimeInterface', 'format'=>'string'],
],
'dom_import_simplexml' => [
'old' => ['DOMElement|null', 'node'=>'SimpleXMLElement'],
'new' => ['DOMElement', 'node'=>'SimpleXMLElement'],
],
Comment on lines +312 to +315
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was a null return possible in PHP < 8.0 when using correct parameters? If the only time null is returned is because the parameters are invalid and Psalm correctly catches that we can exclude the null return value (it's basically there because PHP before 8.0 was really lenient on some function calls and returned null instead of throwing an error for incorrect arguments, eg https://3v4l.org/W9kUt).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From looking at the old source code, it could return null if the supplied nodetype was invalid. (This behavior was changed in php/php-src@8fef83d)

if (nodep && nodeobj && (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE)) {
	DOM_RET_OBJ((xmlNodePtr) nodep, &ret, (dom_object *)nodeobj);
} else {
	php_error_docref(NULL, E_WARNING, "Invalid Nodetype to import");
	RETURN_NULL();
}

Edit: If i'm reading the old source code correctly atleast. As my C knowledge is limited.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me then :)

'explode' => [
'old' => ['list<string>|false', 'separator'=>'string', 'string'=>'string', 'limit='=>'int'],
'new' => ['list<string>', 'separator'=>'string', 'string'=>'string', 'limit='=>'int'],
Expand Down
2 changes: 1 addition & 1 deletion dictionaries/CallMap_historical.php
Expand Up @@ -10391,7 +10391,7 @@
'dom_document_schema_validate' => ['bool', 'source'=>'string', 'flags'=>'int'],
'dom_document_schema_validate_file' => ['bool', 'filename'=>'string', 'flags'=>'int'],
'dom_document_xinclude' => ['int', 'options'=>'int'],
'dom_import_simplexml' => ['DOMElement|false', 'node'=>'SimpleXMLElement'],
'dom_import_simplexml' => ['DOMElement|null', 'node'=>'SimpleXMLElement'],
'dom_xpath_evaluate' => ['', 'expr'=>'string', 'context'=>'DOMNode', 'registernodens'=>'bool'],
'dom_xpath_query' => ['DOMNodeList', 'expr'=>'string', 'context'=>'DOMNode', 'registernodens'=>'bool'],
'dom_xpath_register_ns' => ['bool', 'prefix'=>'string', 'uri'=>'string'],
Expand Down