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

DOMDocument::$preserveWhitespace should be reported as dynamic property. Not $preserveWhiteSpace #8915

Closed
sasezaki opened this issue Dec 17, 2022 · 5 comments · Fixed by #8918
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm good first issue internal stubs/callmap

Comments

@sasezaki
Copy link
Contributor

Hi. I noticed that psalm would not report DOMDocument::$preserveWhitespace is dynamic property.
( When after I saw this commit php/doc-base@9965c2b )

php-src declares as preserveWhiteSpace .
https://github.com/php/php-src/blob/027add9e1bf935c2d874f736105cced87fdeb226/ext/dom/php_dom.stub.php#L679

<?php

$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->preserveWhitespace = false; // should be reported as dynamic property

$dom->PreserveWhitespace = false; // ERROR: UndefinedPropertyAssignment
$dom->preservewhitespace = false; // ERROR: UndefinedPropertyAssignment

// PropertyMap  `'strictErrorChecking' => 'bool',` 
$dom->strictErrorChecking = false;
$dom->strictErrorchecking = false;

https://psalm.dev/r/a2760ed2e5

It seems current PropertyMap is mistaken.

'preserveWhitespace' => 'bool',

'preserveWhitespace' => 'bool',

But I don't know why currently $dom->preserveWhiteSpace is not reported as ERROR against case sensitive...

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/a2760ed2e5
<?php

$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->preserveWhitespace = false; // should be reported as dynamic property

$dom->PreserveWhitespace = false;
$dom->preservewhitespace = false;

// PropertyMap  `'strictErrorChecking' => 'bool',` 
$dom->strictErrorChecking = false;
$dom->strictErrorchecking = false;
Psalm output (using commit ef02ded):

ERROR: UndefinedPropertyAssignment - 7:1 - Instance property DOMDocument::$PreserveWhitespace is not defined

ERROR: UndefinedPropertyAssignment - 8:1 - Instance property DOMDocument::$preservewhitespace is not defined

ERROR: UndefinedPropertyAssignment - 12:1 - Instance property DOMDocument::$strictErrorchecking is not defined

@weirdan
Copy link
Collaborator

weirdan commented Dec 17, 2022

Psalm seems to think both are present: https://psalm.dev/r/3015ffd278

image

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/3015ffd278
<?php

$dom = new DOMDocument;
$v = get_object_vars($dom);        
/** @psalm-trace $v */;
Psalm output (using commit ef02ded):

INFO: Trace - 5:23 - $v: array{actualEncoding: null|string, attributes: DOMNamedNodeMap|null, baseURI: null|string, childElementCount: int, childNodes: DOMNodeList<DOMNode>, config: mixed, doctype: DOMDocumentType|null, documentElement: DOMElement|null, documentURI: null|string, encoding: null|string, firstChild: DOMNode|null, firstElementChild: DOMElement|null, formatOutput: bool, implementation: DOMImplementation, lastChild: DOMNode|null, lastElementChild: DOMElement|null, localName: null|string, namespaceURI: null|string, nextSibling: DOMNode|null, nodeName: string, nodeType: int, nodeValue: null|string, ownerDocument: DOMDocument|null, parentNode: DOMNode|null, prefix: string, preserveWhiteSpace: bool, preserveWhitespace: bool, previousSibling: DOMNode|null, recover: bool, resolveExternals: bool, standalone: bool, strictErrorChecking: bool, substituteEntities: bool, textContent: string, validateOnParse: bool, version: null|string, xmlEncoding: null|string, xmlStandalone: bool, xmlVersion: null|string, ...<string, mixed>}

INFO: UnusedVariable - 4:1 - $v is never referenced or the value is not used

@weirdan
Copy link
Collaborator

weirdan commented Dec 17, 2022

'preserveWhiteSpace' likely comes from reflection, while 'preserveWhitespace' is from the property map.

@sasezaki
Copy link
Contributor Author

@weirdan

Thanks for advice! I made PR at #8918.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm good first issue internal stubs/callmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants