0

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
  • Yes, look at __call, which catches any calls to methods that do not exist. You can make a dynamic call using $method = 'callme'; $this->$method($params). Commented Nov 21, 2013 at 23:56
  • Can you concretise the use case / context? Commented Nov 22, 2013 at 0:00

2 Answers 2

0

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

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.