Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[TypeInfo] Fix handling ConstFetchNode #60820

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
wants to merge 1 commit into
base: 7.2
Choose a base branch
from

Conversation

norkunas
Copy link
Contributor

@norkunas norkunas commented Jun 18, 2025

Q A
Branch? 7.2
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #...
License MIT

I cannot upgrade to 7.3 because I get:

  In StringTypeResolver.php line 88:
!!                                                                                 
!!    Cannot resolve "array{requirement: ProductLicense::SYSTEM_REQUIREMENT_*, va  
!!    lue: non-empty-string}".                                                     
!!                                                                                 
!!  
!!  In StringTypeResolver.php line 142:
!!                                                                                 
!!    Unhandled "PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode" constant expr  
!!    ession.                                                                      
!!                                                                                 

@carsonbot

This comment was marked as outdated.

@carsonbot carsonbot added this to the 7.4 milestone Jun 18, 2025
@norkunas norkunas changed the base branch from 7.4 to 7.2 June 18, 2025 11:22
@norkunas
Copy link
Contributor Author

Hmm, this is not the right fix :(

@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch from 38d6ac6 to 526b002 Compare June 18, 2025 11:26
@norkunas norkunas requested a review from dunglas as a code owner June 18, 2025 11:26
@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch from 526b002 to 6e237a9 Compare June 18, 2025 11:42
@norkunas
Copy link
Contributor Author

Changed implementation from returning Type::string() to any union-scalar

@stof
Copy link
Member

stof commented Jun 18, 2025

Constants are not even restricted to scalars in recent PHP versions.

The right fix would involve looking at the fetched constants.

@OskarStark OskarStark changed the title [TypeInfo] Fix handling ConstFetchNode [TypeInfo] Fix handling ConstFetchNode Jun 18, 2025
@OskarStark OskarStark modified the milestones: 7.4, 7.2 Jun 18, 2025
@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch from 6e237a9 to 48f648b Compare June 19, 2025 09:55
@norkunas
Copy link
Contributor Author

I've updated implementation

@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch 3 times, most recently from 4173b66 to 606a4ab Compare June 19, 2025 10:23
@norkunas norkunas force-pushed the typeinfo-const-fetch-node branch from 606a4ab to 3d5c90d Compare June 19, 2025 10:48
if (preg_match('/^'.str_replace('\*', '.*', preg_quote($node->constExpr->name, '/')).'$/', $const->getName())) {
$constValue = $const->getValue();

$types[] = match (true) {
Copy link
Contributor

@mtarld mtarld Jun 19, 2025

Choose a reason for hiding this comment

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

Maybe you can use Type::fromValue() instead? And then merge types with CollectionType::mergeCollectionValueTypes() helper method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted, but it's not available in 7.2

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh indeed, then it might be great to use that starting from 7.3 I guess.

@norkunas
Copy link
Contributor Author

I'm not sure how to fix the failing serializer test. For me it looks like that it's an invalid test, because it defines self::* on an anonymous class but does not define any constant. Then later of course it fails because it's an union type, but for now when no matched constants were found it returns Type::null and as property defines also null, it tries to pass Type::null to Type::union twice.

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

Successfully merging this pull request may close these issues.

5 participants