Skip to content

Classname in instanceof cannot be null#2769

Closed
staabm wants to merge 3 commits intophpstan:1.10.xfrom
staabm:instanceof-null
Closed

Classname in instanceof cannot be null#2769
staabm wants to merge 3 commits intophpstan:1.10.xfrom
staabm:instanceof-null

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Nov 23, 2023


public function sayMixed(mixed $class): void
{
var_dump(new stdClass instanceof $class);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

was not sure whether we want the rule error on mixed


public function processNode(Node $node, Scope $scope): array
{
if (!$node->class instanceof Node\Name) {
Copy link
Copy Markdown
Contributor Author

@staabm staabm Nov 23, 2023

Choose a reason for hiding this comment

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

maybe this needs to be BleedingEdge only? reworked into a level 8 rule instead

@ondrejmirtes
Copy link
Copy Markdown
Member

There are many other invalid things that can't be in instanceof: https://3v4l.org/6h0tt

This can't just be a level 8 rule. Stuff like this needs to be reported sooner: https://phpstan.org/r/caf262f8-6927-4288-8ce0-09da00a1dd1d

mixed should be reported on level 9.

To help with that you need to use RuleLevelHelper.

@staabm staabm closed this Jul 24, 2025
@staabm staabm deleted the instanceof-null branch July 24, 2025 15:08
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

Successfully merging this pull request may close these issues.

2 participants