-
-
Notifications
You must be signed in to change notification settings - Fork 184
Conversation
https://www.php.net/manual/en/function.class-implements.php The second parameter is boolean. I understand that there will be a cast, but still.
src/Attributes/CastWith.php
Outdated
@@ -15,7 +15,7 @@ public function __construct( | |||
public string $casterClass, | |||
mixed ...$args | |||
) { | |||
if (! class_implements($this->casterClass, Caster::class)) { | |||
if (! class_implements($this->casterClass, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be this then, I think:
if (! class_implements($this->casterClass, true)) { | |
if (! in_array(Caster::class, class_implements($this->casterClass, true), true) { |
Or maybe:
if (! class_implements($this->casterClass, true)) { | |
if (! is_a($this->casterClass, Caster::class, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that it will always be true here. A list of interfaces is also required here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. But I don't think the check makes sense at all. Would be strange to check if $this->casterClass
just implements something. The intention was probably to check if it implements Caster::class
.
That's absolutely my bad; it should have been |
@@ -15,7 +15,7 @@ public function __construct( | |||
public string $casterClass, | |||
mixed ...$args | |||
) { | |||
if (! class_implements($this->casterClass, Caster::class)) { | |||
if (! is_subclass_of($this->casterClass, Caster::class)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need the third parameter to be true
here, because the first one is a string.
if (! is_subclass_of($this->casterClass, Caster::class)) { | |
if (! is_subclass_of($this->casterClass, Caster::class, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What for? There is true by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right! I was confused because for is_a()
it's default false
....
Thanks! |
Why class name?
https://www.php.net/manual/en/function.class-implements.php
The second parameter is boolean. I understand that there will be a cast, but still.