Skip to content
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

Create a IsA expression #396

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hgraca
Copy link
Contributor

@hgraca hgraca commented Jul 26, 2023

This will allow for testing if a class extends or
implements another code unit, anywhere in the inheritance tree.

Comment on lines 47 to 48
\is_a($theClass->getFQCN(), $allowedFqcn, true)
|| \is_subclass_of($theClass->getFQCN(), $allowedFqcn)

Choose a reason for hiding this comment

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

Do we really need to check both? Both do the same, except that is_a() also returns true for the class itself (like is_a(A::class, A::class)), AFAIK, so is_subclass_of() should never be called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunately, is_a doesnt check for interface implementation, and is_subclass_of doesnt check for same class. :(

Choose a reason for hiding this comment

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

unfortunately, is_a doesn't check for interface implementation

I think it does: https://3v4l.org/91Yt8

AFAIK, is_a does the same as instanceof (and it is even more powerful, since it can check string class names and not only instances, if the third parameter is true).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HAH! u r correct, I will fix this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed and force pushed

This will allow for testing if a class extends or
implements another code unit, anywhere in the inheritance tree.
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.

None yet

3 participants