Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Avoid false error on is_subclass_of #4472

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
VincentLanglet wants to merge 2 commits into phpstan:2.1.x
base: 2.1.x
Choose a base branch
Loading
from VincentLanglet:isSubClass

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Oct 23, 2025
edited
Loading

Closes phpstan/phpstan#13713

Solves phpstan/phpstan#6305 (comment)

Partially revert #1044 cc @herndlm

I don't think we can resolve the original request of phpstan/phpstan#6305 (comment) without introducing lot of false positive, like shown by this PR.

}

return TypeTraverser::map(
$isUncertain = $classType->getConstantStrings() === [];
Copy link
Contributor Author

@VincentLanglet VincentLanglet Oct 24, 2025

Choose a reason for hiding this comment

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

From the original check

// prevent false-positives in IsAFunctionTypeSpecifyingHelper
		if ($classType->getConstantStrings() === [] && $resultType->isSuperTypeOf($objectOrClassType)->yes()) {
			return new SpecifiedTypes([], []);
		}

@VincentLanglet VincentLanglet marked this pull request as ready for review October 24, 2025 17:33
Copy link
Collaborator

This pull request has been marked as ready for review.

'Call to function is_subclass_of() with Bug6305\B and \'Bug6305\\\A\' will always evaluate to true.',
11,
],
// [
Copy link
Contributor Author

@VincentLanglet VincentLanglet Oct 24, 2025

Choose a reason for hiding this comment

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

Currently this is too complicated to be detected since we don't make a difference in ObjectType between the exact class and one of the children.


function debug(object $object): void {
if ($object instanceof \stdClass) {
echo var_export(\is_subclass_of($object, \stdClass::class, false), true) . \PHP_EOL;
Copy link
Contributor Author

@VincentLanglet VincentLanglet Oct 24, 2025

Choose a reason for hiding this comment

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

With this PR there is no error here which fix phpstan/phpstan#13713
but I dunno why the bot is not detecting the change...

Copy link
Contributor Author

This issue was more complicated than expected... I'm not against your opinion/review @staabm :)

staabm reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

PHPStan incorrectly narrows type of object after an instanceof check

AltStyle によって変換されたページ (->オリジナル) /