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_
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_
Try:
Note that
===
is necessary here.==
won't work, sincestrpos()
returnsfalse
if no match was found. Due to PHPs dynamic typing this is equal to0
and therefore a strict (type safe) equality check is needed.I would suggest something a bit more flexible such as this (unless the method names are dynamic or are unknown):
Outputs:
You can use
preg_grep()
to filter them:Why don't you just make your own function that loops through the array from get_class_methods() and tests each element against "bla_" and returns a new list with each matching value?