0

This currently works:

    $get_pending_list_action = "get_pending_list_".$action;
    $data = $this->sectorswaps->{$get_pending_list_action}($list);

Is there anyway to make it so I can turn this into one line?

i.e. this does NOT work:

    $data = $this->sectorswaps->get_pending_list_{$action}($list);

Is there some other way that I dont know of?

6
  • Is a one liner more important than readability? Commented Oct 14, 2012 at 14:38
  • did you try: $data = $this->sectorswaps->{"get_pending_list_".$action}($list); Commented Oct 14, 2012 at 14:40
  • @MattWhipple - thanks matt - its so obvious now. if you can post that as the answer - i'll accept Commented Oct 14, 2012 at 14:43
  • 1
    @MarkBaker: There is nothing wrong about learning new things.. Commented Oct 14, 2012 at 14:43
  • 1
    A one-liner might be easier for you to read when it's fresh in your mind, and you know what you're expecting.... doesn't necessarily make it easier for others to read and understand, or for you to remember it in 6 months time. There's nothing wrong with learning new things, but new isn't always better... more important to learn the how to code in a way that you and others can subsequently maintain with ease... if a one-liner is "better", then use it; but knowing when to use more than one line for readability is also a coding skill. Commented Oct 14, 2012 at 14:48

1 Answer 1

2

$data = $this->sectorswaps->{"get_pending_list_".$action}($list);

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.