Re: [PATCH] array_get()
| From: | Robert Cummings | Date: | Wed, 12 Sep 2007 18:05:12 +0000 |
| Subject: | Re: [PATCH] array_get() | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-32301@lists.php.net to get a copy of this message | ||
On Wed, 2007-09-12 at 13:53 -0400, Andrew Shearer wrote:
>
>
> Here is the patch and unit test file for array_get():
>
>
> http://ashearer.com/software/array_get/2007-09-10-php6/array_get.diff
>
> http://ashearer.com/software/array_get/2007-09-10-php6/array_get.phpt
>
>
> And here is the backward compatibility function:
>
> if (!function_exists('array_get')) {
> function array_get($arr, $key, $default = false) {
> if (array_key_exists($key, $arr)) {
> return $arr[$key];
> }
> else {
> return $default;
> }
> }
> }
IMHO the default value for $default should be null. That way it has the
same return value as using an undefined index on an array.
Comments?
Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................