1

Here is the scenario:

I have a class with no predetermined amount of methods. Some will be function actionName and others will be called function filterName where "filter" and "action" will define what type of method they are and "Name" can be anything.

In my __construct() I want to:

$methods = get_class_methods($this); foreach ( $methods as $method ) { if ( $method == 'action' ) $this->DoSomething( $this->{$method}() ); if ( $method == 'filter' ) $this->DoSomethingElse( $this->{$method}() ); } 

How can I achieve this without using any type of string or reg expressions?

I am also open to using an alternative to get_class_methods(). But remember I will never know how many "action" or "filter" methods exists.

1 Answer 1

1
if (substr($method,0,6) == "action") { } if (substr($method,0,6) == "filter") { } 

I'm simply checking the first six character-chain on the name of the function for the keywords. Be warned - too many keywords will kill the performance of this.

Sign up to request clarification or add additional context in comments.

3 Comments

I might be reading this wrong but the main reason I do not want to use any type of str search because if you look at Benchmarks it gives off the impression that just 80 loops takes about 1 second. That to me sounds like a hell of a-lot of over head... In my example I very well could have over 100 methods. It's something I can never predict or know.
In terms of "other methods", I have rarely seen a method able to discern strings without actually using any kind of string comparison to do so. There are no handy flags that you could use, so the only thing left is a lookup table :-(
Basically I want to do function {type}name () {} and then if ( functionType($fName) == 'action' ) {...}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.