Web lists-archives.com

[PHP] Re: A 'missing' PHP primitive?






Hi, I'm wondering if there is any built-in PHP primitives to perform the
same task as this simple, almost trivial function:

function get(&$var) {
      return $var;
}

?


It is useful for accessing arrays where some fields may be unset.  For
example:

As of PHP 7.0.0 there is the null coalescing opertor, so you can write:

   $arr[1] ?? NULL

It seems like there should be a built in primitive called 'get' or
'ifset' that does this task.
See
<https://nikic.github.io/2014/01/10/The-case-against-the-ifsetor-function.html>.


Thanks, perfect answer. The PHP 7 operator is the built in way to go. Unlike my function, or the ones described in the link, it DOES NOT silently create NULL keys in the fields it checks. So the other methods are inferior unless one actually wishes to do that.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php