Accept ::class as literal string#1692
Conversation
|
I disagree with this fix. class-string isn't always literal string. |
@craigfrancis didn't give an example of class-string which are not literal-string in phpstan/phpstan-doctrine#332 (comment) But I think we should follow the way it's handled by psalm |
// $s is string
if (class_exists($s)) {
// should $s suddenly be a literal-string?
} |
|
[I’m out atm, and using phone, will try to check properly later] The source of the variable has to be a literal, so if you got it from |
|
That's what I thought, so this PR has to be fixed with my suggestion. Thank you. |
26d06aa to
e71a0dc
Compare
|
thanks for the input guys. I just committed an update. |
|
The spurious out of memory error could also be observed on other PRs. I don‘t think it is related to the actual change |
There was a problem hiding this comment.
ConstantStringType is already considered to be a literal string, so intersecting with AccessoryLiteralStringType will just remove the AccessoryLiteralStringType again.
ondrejmirtes
left a comment
There was a problem hiding this comment.
I'd say that the ifs above should also be covered by this PR. Basically any $obj::class is a literal-string.
So with $obj::class and $obj being EnumCaseObjectType, it should also be literal-string. And with $type instanceof TemplateType && !$type instanceof TypeWithClassName that should work too.
|
adjusted per feedback. I am thinking whether a /**
* @param object $o
*/
function a($o): void
{
assertType('class-string&literal-string', $o::class);
sayHello($o::class);
} |
|
Of course :) |
|
Please rebase and solve the conflict, I'll merge it then. |
|
Thank you! |
closes phpstan/phpstan#7823
closes phpstan/phpstan-doctrine#332