Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:102285
Return-Path: <enno.woortmann@web.de>
Mailing-List: contact internals-help@lists.php.net; run by ezmlm
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 84387 invoked from network); 17 Jun 2018 22:09:26 -0000
Received: from unknown (HELO lists.php.net) (127.0.0.1)
  by localhost with SMTP; 17 Jun 2018 22:09:26 -0000
Authentication-Results: pb1.pair.com smtp.mail=enno.woortmann@web.de; spf=pass; sender-id=pass
Authentication-Results: pb1.pair.com header.from=enno.woortmann@web.de; sender-id=pass
Received-SPF: pass (pb1.pair.com: domain web.de designates 212.227.17.12 as permitted sender)
X-PHP-List-Original-Sender: enno.woortmann@web.de
X-Host-Fingerprint: 212.227.17.12 mout.web.de  
Received: from [212.227.17.12] ([212.227.17.12:33737] helo=mout.web.de)
	by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP
	id 74/4F-29356-51CD62B5 for <internals@lists.php.net>; Sun, 17 Jun 2018 18:09:26 -0400
Received: from [192.168.0.51] ([77.21.86.66]) by smtp.web.de (mrweb102
 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MYO45-1fi69a1Fsf-00V8pR; Mon, 18
 Jun 2018 00:09:15 +0200
To: Alice Wonder <alice@librelamp.com>, internals@lists.php.net
References: <75db877c-ef0b-7d3b-48a8-9879d90352b0@web.de>
 <7052a9c2-7c19-a382-8967-8fda648569df@blueyonder.co.uk>
 <d995c81f-3f51-93b3-d861-20b4462f6891@librelamp.com>
Message-ID: <76e4744f-6722-ee49-0325-e4433236f1b1@web.de>
Date: Mon, 18 Jun 2018 00:09:11 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101
 Thunderbird/52.8.0
MIME-Version: 1.0
In-Reply-To: <d995c81f-3f51-93b3-d861-20b4462f6891@librelamp.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Antivirus: Avast (VPS 180617-4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wyPZ36Qfchpvl9wgM9+/BHRWg0N
 KfEauNmC2fu091zxttJVmVkJWokJDzpgYxVF+c0/MVW6gn9UcKkfv+0PIE+hfcsoOl9/Nv7+M
 GYh59z3
Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()
 and array_key_last()
From: enno.woortmann@web.de (Enno Woortmann)

Hi Alice,


Am 17.06.2018 um 22:16 schrieb Alice Wonder:
> boolean is a value, null is the absence of a value, which is more=20
> accurate, no?

In my opinion that's the argument to return null for either parameters=20
which aren't an array or empty arrays simply because a first/last key=20
isn't present and null is the value to be returned for an undefined state=
=2E
I've tested this behavior with other array_* functions which are=20
provided in the PHP core and they provide null consistently, eg.:

root@WOL-Soft-DEVVM:/var/www/WOL-Soft# php -r "var_dump(array_keys(1));"
PHP Warning:=C2=A0 array_keys() expects parameter 1 to be array, integer =

given in Command line code on line 1
NULL
root@WOL-Soft-DEVVM:/var/www/WOL-Soft# php -r=20
"var_dump(array_values('hello'));"
PHP Warning:=C2=A0 array_values() expects parameter 1 to be array, string=
=20
given in Command line code on line 1
NULL
root@WOL-Soft-DEVVM:/var/www/WOL-Soft# php -r "var_dump(array_flip(null))=
;"
PHP Warning:=C2=A0 array_flip() expects parameter 1 to be array, null giv=
en=20
in Command line code on line 1
NULL

There was another remark which wasn't sent to the internals mail list=20
but to my personal mail account (mehh :( ) which supported to return fals=
e:

"because a lot of functions act the way returning false when things go
wrong even when they normally only would return string/int/array which
should be justification enough: consistency"

An example for this argument was the function strpos which may be=20
checked with =3D=3D=3D or !=3D=3D against false.
But the real discussion about the return value and the facility of=20
comparison against another value is only interesting if we extend the=20
scope of this RFC to cover also array_value_(first|last), as null as an=20
array key is not supported and will be casted to an empty string. Due to =

this internal handling of array keys, null is for the functions=20
array_key(first|last) an unique return value to evaluate failures.

My opinion about this subject supports your argument as null is the=20
value which should be returned if the requested value is not defined. If =

a variable which is neither an array nor an array with entries is passed =

neither the first/last key nor the first/last value is a defined value=20
and thus null should be the return value.

Especially if we decide to extend the scope of this RFC to cover also=20
array_value_(first|last) there is no possibility to provide a return=20
value which doesn't collide with a possible array value. If cases occur=20
which may resolve into a collision, the usage of functions like=20
is_array() and empty()/count() is inevitable as both null and false are=20
valid values for an array value. To argument with the semantic of false=20
and null the correct return value should be null for each of the=20
proposed functions (as well the proposed functions which are currently=20
covered by the RFC as the extended version which also covers the methody =

array_value(first|last) ) as null defines an undefined value.

Regards,
Enno