Skip to content

Fix ::class on string expression#1425

Merged
ondrejmirtes merged 1 commit intophpstan:1.8.xfrom
rvanvelzen:constant-string-class
Sep 2, 2022
Merged

Fix ::class on string expression#1425
ondrejmirtes merged 1 commit intophpstan:1.8.xfrom
rvanvelzen:constant-string-class

Conversation

@rvanvelzen
Copy link
Copy Markdown
Contributor

@rvanvelzen rvanvelzen commented Jun 15, 2022

No description provided.

@ondrejmirtes
Copy link
Copy Markdown
Member

I think this code pattern isn't supported: https://3v4l.org/MM1pJ

@rvanvelzen
Copy link
Copy Markdown
Contributor Author

Absolutely right, but strangely enough this is: https://3v4l.org/Rb3oU

@ondrejmirtes
Copy link
Copy Markdown
Member

Whaat!? :) Sounds like an inconsistency that should be reported in https://github.com/php/php-src/issues :)

I just did: php/doc-en#1646

@rvanvelzen rvanvelzen marked this pull request as draft June 16, 2022 13:33
@rvanvelzen
Copy link
Copy Markdown
Contributor Author

I'll let this sit here until php/doc-en#1646 is resolved :)

@ondrejmirtes
Copy link
Copy Markdown
Member

So the conclusion in php/doc-en#1646 is unequivocal :) Can you please add a test that 'Foo'::class is not reported by ClassConstantRule and this example is reported?

$foo = 'Foo';
var_dump($foo::class);

And maybe also assertType() for this example too to make sure we have an ErrorType there.

Thanks :)

@rvanvelzen rvanvelzen force-pushed the constant-string-class branch from 5b30b6e to bb30737 Compare September 2, 2022 06:48
@rvanvelzen rvanvelzen changed the base branch from 1.7.x to 1.8.x September 2, 2022 06:48
@rvanvelzen
Copy link
Copy Markdown
Contributor Author

The error cases are already covered by tests, so this should be ready to go :)

@rvanvelzen rvanvelzen marked this pull request as ready for review September 2, 2022 06:49
@staabm
Copy link
Copy Markdown
Contributor

staabm commented Sep 2, 2022

Absolutely right, but strangely enough this is: 3v4l.org/Rb3oU

may I ask how you realized this is a thing? did you see such code somewhere?

@rvanvelzen
Copy link
Copy Markdown
Contributor Author

I stumbled upon it while fumbling around with phpstan/phpstan#7391 😅

@ondrejmirtes ondrejmirtes merged commit 42a9252 into phpstan:1.8.x Sep 2, 2022
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

@rvanvelzen rvanvelzen deleted the constant-string-class branch September 6, 2022 09:31
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.

3 participants