1

Im using a simple __call function , to dynamicly get and set my properties and im searching for a way to use something easier then this:

$setKey = "set".ucfirst($key);
$this->$setKey($foo);

is there a way to use something like

$this->"set".ucfirst($key)($foo);
1
  • $this->{"set".ucfirst($key)}($foo) Commented Nov 16, 2012 at 13:39

1 Answer 1

3

Yes. You have to use braces:

$this->{"set".ucfirst($key)}($foo);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it works! now my code looks atleast a bit better! I´ll accept your answer after the timer has finished!

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.