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

PHPStan assumes DOMDocument::load() returns mixed #10057

Closed
tschoonen opened this issue Oct 26, 2023 · 10 comments · Fixed by phpstan/phpstan-src#2975
Closed

PHPStan assumes DOMDocument::load() returns mixed #10057

tschoonen opened this issue Oct 26, 2023 · 10 comments · Fixed by phpstan/phpstan-src#2975
Labels
Milestone

Comments

@tschoonen
Copy link

Bug report

PHPStan seems to assume that DOMDocument::load() returns mixed and not bool as stated in the documentation.

https://www.php.net/manual/en/domdocument.load.php

The documentation does however mention from version 8.3 onwards it will return a "tentative bool" whatever that may mean (quantum bits?). But I get the error even though I have explicitly specified the PHP version as 8.1.

Code snippet that reproduces the problem

https://phpstan.org/r/00db931e-075f-4f74-8f2f-58df9e3003db

Expected output

No errors.

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

PHPStan helps me everyday by saving me from my own errors.

@ondrejmirtes
Copy link
Member

Please send a PR that updates resources/functionMap.php in phpstan-src.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-5: Only booleans are allowed in a negated boolean, mixed given.
+5: Only booleans are allowed in a negated boolean, bool|DOMDocument given.
Full report
Line Error
5 `Only booleans are allowed in a negated boolean, bool

@VincentLanglet
Copy link
Contributor

Please send a PR that updates resources/functionMap.php in phpstan-src.

I've open phpstan/phpstan-src#2975

But seems like for PHP 8, it's now inferred from the phpstan/php-8-stubs lib, but the type is bool|DOMDocument when it should be bool.
https://github.com/phpstan/php-8-stubs/blob/main/stubs/ext/dom/DOMDocument.php#L82-L88

I dunno if this issue need to stay open or move to phpstan/php-8-stubs lib.

Same issue for loadHTML, loadHTMLFile or loadXML.

@ondrejmirtes
Copy link
Member

If phpstan/php-8-stubs says the type is bool|DOMDocument then it really is bool|DOMDocument. These stubs are extracted from official stubs in php-src.

If that's wrong then you should open a bug report in php-src.

@VincentLanglet
Copy link
Contributor

If phpstan/php-8-stubs says the type is bool|DOMDocument then it really is bool|DOMDocument. These stubs are extracted from official stubs in php-src.

What I don't understand is the fact that phpstan/php-8-stubs say bool|DomDocument
https://github.com/phpstan/php-8-stubs/blob/main/stubs/ext/dom/DOMDocument.php#L84

but php-src say bool
https://github.com/php/php-src/blob/952cc2a675d429aa428a5ffaafb1c04e1a4736ce/ext/dom/php_dom.stub.php#L821-L822

So I thought the bug was in php-8-stubs.

@ondrejmirtes
Copy link
Member

Interesting, you can try to debug the stubs extractor and see why it happens. There's a potential for a lot of bugs being fixed.

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Mar 19, 2024

Interesting, you can try to debug the stubs extractor and see why it happens. There's a potential for a lot of bugs being fixed.

I find out the issue, it's not really an extractor bug.

PHPDoc was wrong on PHP-8.0, PHP-8.1 and PHP-8.2 but is correct in PHP-8.3 branch.
Cf php/php-src@ae66a0d#diff-b491d14be46a424b441ce330165556a626fdb90a52cfc64f8553945bd28a3e2fR205-R209

I've opened php/php-src#13762 but I dunno if it will be accepted or if we'll require a fix on the extractor side.

@VincentLanglet
Copy link
Contributor

As expected @ondrejmirtes a fix on PHP-8.0 and PHP-8.1 won't be accepted
php/php-src#13762 (comment)

Is it possible to ignore
'stubs/ext/dom/DOMDocument.php' on PHP branche 8.0, 8.1 and 8.2 in the extractor ?

@ondrejmirtes
Copy link
Member

Fixed by phpstan/phpstan-src#2975

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants