Re: A 'missing' PHP primitive?

From: Date: Wed, 09 Nov 2016 16:17:09 +0000
Subject: Re: A 'missing' PHP primitive?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-325830@lists.php.net to get a copy of this message
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.

« previous php.general (#325830) next »