I find myself constantly writing if statements like the following:
if(isset($this->request->data['Parent']['child'])){ $new_var['child'] = $this->request->data['Parent']['child']; }
My question is, without creating a new shorter variable before the if
statement, is there a magic php process that will help avoid having to rewrite $this->request->data['Parent']['child']
in the body of the if statement? I also want to keep the code clean for any successor developers.
I am also not looking for a ternary solution.
Something a little more along the lines of jquery’s use of this
. (That I know of) php doesn’t allow anonymous functions or it’s not common practice and I’m not saying I want a bunch of anonymous functions all over my classes either.
UPDATE Added in php 7 What does double question mark (??) operator mean in PHP
Advertisement
Answer
This would be extremly cool, but unfortunaly nothing can do it.
Maybe some plugin for some IDE can help you doing stuff like that.
What I can suggest on this case is what I do personally, without touching mouse move cursor with the arrows near $this
then hold CTRL + SHIFT and right arrow and you will be selecting more stuff at once. (Then just use ctrl+c and ctrl+v to copy paste)
Of course this applies to every languages, not only PHP