Snapey

php variable function

Posted 1 year ago by Snapey

I have this ugly bit of code but can't seem to find the right syntax to simplify it

    $r=$request->response;
    $this->$r($task);

$request->response is a string corresponding to one of three buttons on a form. The buttons have values of 'approve', 'query' and 'refuse'

in the snippet I am trying to call a function that has the name specified in the request. So, if the user presses 'approve' then $this->approve() is called

I tried $this->$request->response($task); but the syntax is not right.

it works as I have it now but it's annoying me everytime I see that $r variable

and, yes, my form request validates that response can only be one of the three method names.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.