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

Helper function to check if method overwritten in child class #12631

Closed
foremtehan opened this issue Nov 8, 2023 · 3 comments
Closed

Helper function to check if method overwritten in child class #12631

foremtehan opened this issue Nov 8, 2023 · 3 comments

Comments

@foremtehan
Copy link

Description

It would be great if we could have a method that checks whether the child class overwritten the parent class's method

https://3v4l.org/hTQWO

As you can see in the above script, The method_exists return true even the method not overwritten in the child class, Not that passing static::class, self::class and $this don't solve the problem

@foremtehan foremtehan changed the title Method to check if method overwritten in child class Helper function to check if method overwritten in child class Nov 8, 2023
@nielsdos
Copy link
Member

nielsdos commented Nov 8, 2023

I'm curious, why do you need this feature? Are you looking for the Override attribute?

@iluuu1994
Copy link
Member

iluuu1994 commented Nov 8, 2023

There's ReflectionMethod::hasPrototype(). It indicates whether the declared method is overriding some other declaration (including interface methods). There's also getPrototype() to get the class/interface that declares it (at the top-most level). Does that suffice? This seems like a fringe case, so a little helper function should serve you well. I don't think this is common enough to justify a new function.

@foremtehan
Copy link
Author

@iluuu1994, thank you. It works as expected. sad to see that it only works in 8.2 >=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants