0

I have a very specific question: is the following code possible in one line? Or is there a beter way to do the same?

$key = rand(1,100);

$temp = 'GetObjects'.ucfirst($key).'Array';
$objects = $this->module->$temp();

Like this:

$objects = $this->module->'GetObjects'.ucfirst($key).'Array'();
2
  • Honestly, you have that many methods on your module that 1-100 works? Good god! Commented Nov 18, 2010 at 18:22
  • No, $key is an example it has 1-20 methods or so. Commented Nov 18, 2010 at 18:32

1 Answer 1

4

Maybe

$objects = $this->module->{'GetObjects'.ucfirst($key).'Array'}();

or

$objects = call_user_func(array($this->module, 'GetObjects'.ucfirst($key).'Array'));
Sign up to request clarification or add additional context in comments.

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.