Alex Rivera | Logout

Assign if variable is set

Asked 2012-11-29T13:01:59.123
31

In PHP I find myself writing code like this frequently:

$a = isset($the->very->long->variable[$index])
            ? $the->very->long->variable[$index]
            : null;

Is there a simpler way to do this? Preferably one that doesn't require me to write $the->very->long->variable[$index] twice.

Edit
Report

1 Answer

10

Sadly no, because the RFC has been declined. And because isset is not a function but a language construct you cannot write your own function for this case.

Note: Because this is a language construct and not a function, it cannot be called using variable functions.

answered 2012-11-29T13:05:16.810

Your Answer