Dynamic php method

135 Views Asked by At

Is it possible to create a method dynamically? For example: I have a method called "createMethod()". I would like to pass variables to this method describing how the dynamic method would look like (function description, params as an array or object). I have been trying to make something like that, bet I've got stuck at describing params and got mixed up with eval() function, that I used to form some variables.

Could someone give me a simple example how this dynamic method would look like? Maby there are something helpful already created in Zend or CodeIgniter frameworks?

Thanks!

2

There are 2 best solutions below

0
mcuadros On

You can find a good solution at: php create class method at runtime

Is a mix of the magic method __call and closures.

And this a post about how extending objects with new methods at runtime

0
ilpaijin On

php magic method __call]1 could be what youre looking for