Skip to content

[regression] DOMElement::$attributes is considered nullable #13076

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

Open
Jean85 opened this issue May 26, 2025 · 3 comments
Open

[regression] DOMElement::$attributes is considered nullable #13076

Jean85 opened this issue May 26, 2025 · 3 comments

Comments

@Jean85
Copy link
Contributor

Jean85 commented May 26, 2025

Bug report

Upgrading from 2.1.16 to 2.1.17 facile-it/paraunit#318

I get a regression where DOMElement::$attributes is considered nullable, where it's not. Proof: https://www.php.net/manual/en/class.domnode.php#domnode.props.attributes

The property is nullable for its ancestor (\DOMNode), but not in this case.

Code snippet that reproduces the problem

https://phpstan.org/r/ce94a684-3de4-4a48-9441-b5586c967fac

Expected output

No errors, since it shouldn't be nullable.

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

Totally! So many bug catched early!

@VincentLanglet
Copy link
Contributor

VincentLanglet commented May 27, 2025

The PR JetBrains/phpstorm-stubs#1741 might be wrong ; do you want to provide a PR to revert it @Jean85 ?

But then, we'll get the always true issue reported by
https://phpstan.org/r/a7bb5a31-9cb5-4f07-8ca7-a3d266ad1107

Related PR phpstan/phpstan-src#3800.

There is maybe a bug to fix first with phpstan-assert-if-true

@Jean85
Copy link
Contributor Author

Jean85 commented May 27, 2025

Yes I agree, JetBrains/phpstorm-stubs#1741 IS wrong. That attribute is overriding \DOMNode::$attributes, which is correctly marked as nullable: https://github.com/VincentLanglet/phpstorm-stubs/blob/fed4bb7b17ab85f9365a3a77cf9246d1eb5c1b08/dom/dom_c.php#L76-L81

I'll suggest a revert.

@VincentLanglet
Copy link
Contributor

WIP on PHPStan side phpstan/phpstan-src#4029

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

No branches or pull requests

2 participants