phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Fix ::class on string expression

Open rvanvelzen opened this issue 3 years ago • 5 comments

rvanvelzen avatar Jun 15 '22 13:06 rvanvelzen

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

ondrejmirtes avatar Jun 16 '22 13:06 ondrejmirtes

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

rvanvelzen avatar Jun 16 '22 13:06 rvanvelzen

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

I just did: https://github.com/php/doc-en/issues/1646

ondrejmirtes avatar Jun 16 '22 13:06 ondrejmirtes

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

rvanvelzen avatar Jun 16 '22 13:06 rvanvelzen

So the conclusion in https://github.com/php/doc-en/issues/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 :)

ondrejmirtes avatar Jun 17 '22 07:06 ondrejmirtes

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

rvanvelzen avatar Sep 02 '22 06:09 rvanvelzen

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?

staabm avatar Sep 02 '22 07:09 staabm

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

rvanvelzen avatar Sep 02 '22 07:09 rvanvelzen

Thank you!

ondrejmirtes avatar Sep 02 '22 15:09 ondrejmirtes