Get all method names starting with a substring from a PHP object
You can use preg_grep()
to filter them:
$method_names = preg_grep('/^bla_/', get_class_methods($object));
Try:
$methods = array();
foreach (get_class_methods($myObj) as $method) {
if (strpos($method, "bla_") === 0) {
$methods[] = $method;
}
}
Note that ===
is necessary here. ==
won't work, since strpos()
returns false
if no match was found. Due to PHPs dynamic typing this is equal to 0
and therefore a strict (type safe) equality check is needed.
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?