I have an object and want a method that returns how much method this Object have that start with bla_
.
I found get_class_methods()
which returns all method names, but I only want names which starts with bla_
SomeClass::class will return the fully qualified name of SomeClass including the namespace. This feature was implemented in PHP 5.5. It's very useful for 2 reasons. You can use the use keyword to resolve your class and you don't need to write the full class name.
The ReflectionMethod::invoke() function is an inbuilt function in PHP which is used to invoke the specified reflected method and returns the result of the method. Syntax: public mixed ReflectionMethod::invoke ( $object, $parameter )
Using singleton in PHP Another way to access methods in another class, is to use singleton. This makes it possible to use methods without the need to first instantiate the class. The object is instead created inside the class itself.
You can use preg_grep()
to filter them:
$method_names = preg_grep('/^bla_/', get_class_methods($object));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With