Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102293 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17182 invoked from network); 18 Jun 2018 09:25:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jun 2018 09:25:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.19 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.19 mout.gmx.net Received: from [212.227.15.19] ([212.227.15.19:39787] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 08/33-29356-29A772B5 for ; Mon, 18 Jun 2018 05:25:38 -0400 Received: from [192.168.2.114] ([79.222.35.93]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MNZ9u-1farlA1UuQ-007FC9; Mon, 18 Jun 2018 11:25:30 +0200 To: Enno Woortmann , Alice Wonder , internals@lists.php.net References: <75db877c-ef0b-7d3b-48a8-9879d90352b0@web.de> <7052a9c2-7c19-a382-8967-8fda648569df@blueyonder.co.uk> <76e4744f-6722-ee49-0325-e4433236f1b1@web.de> Message-ID: <73ac8914-8c9f-e74b-a4f5-f6e39cd96f8f@gmx.de> Date: Mon, 18 Jun 2018 11:25:27 +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: <76e4744f-6722-ee49-0325-e4433236f1b1@web.de> Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:urc2tdrkHrJ7MyehvTipV9D4N2I00eaYSbyAj9Xry08kwPq2J/6 XC/lXSEMutYzgQ6n4wpstVy4E0BdQc5hRw3gnJGdFJDxHK0UU4YHSn8R3B6Y6ylPzjn1keV zZGqOTwrGN59p2gPueXozmX9DDvo9lu3TgNKzCKmRXj4ZZjPLKk+DfMJOwhVFHqIm9NFw9F /lTrs12b4uWHE+oj2jfQw== X-UI-Out-Filterresults: notjunk:1;V01:K0:Cxf2EoezmCE=:am9WXsNQ8CmcfWrHHL6pMj eGKjffzKMnAzNflC2dtpTKQu7Nx0gJarMDzFQcpLZm96sX366vBWzcLvaHwFpTbBeOP0LHLkb Y+rYdTMDoQw6hPavfiUudiiSXH6NX3ZOxF0hM+8zL4ydxKGs2YP4PxDldHBi+ahaRR72rgRZE 4C+J8AYdFLtyKDpxLaP8W+7mHy0akB648m4x0kZPjjmD3JnEwBKaYWeTyvEDsIVKoMuZfY6QG efdhor/PgvhpGn1/KgvUozhjJ0tX0sHvqL4lUg1PVP1m0tdc5O+YGZk0ZQYRrMHcCww7l2lqM r9CfYZnR2BybPrbDeC89hujB3t2ItVLdHmrhf//QxLxrAcipvF1l9SF9sq0ZZDHQ+ZEexhCrR 3Ud1hGxQAzkfpjF3oeZxBPRF9Mi6/0uUqFRqS2kUwizlxpPcoFYl0nE9GKGrruKOVGos4Zw8C CKhy0sEicuLFCs+KiREdaXWILVJd5r+euiOBpYcQOIbReIzI7nTj6xGf78yMrL7H75x1awjYu 8csu64SQhPxXeK+HhdKUTvILDINi9FtYim1bbFW2VSMG95q59uW0q+geC585GWrdzBmQftGyC yE5NuoMDYBvQclSyZrn0zdPrK6Rzex4EXD+Nril7KaICHMtwMStf/ERD/g3AYQvdgvJypZnYJ 55igEwAfYonl0SqR6FAj3bmFexWlX2J0xuFfYM1JO3WPuituyBYYFMaYHiDwgu8/7qtF6lsoB W8eeaQ4U/C/qdbi2PdlGxCLna76h+FYpdCRshFO1hKNHB44rgxOX3fyczf4N1Wf4oNATe1jfB fZd5BOc Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()and array_key_last() From: cmbecker69@gmx.de ("Christoph M. Becker") On 18.06.2018 at 00:09, Enno Woortmann wrote: > In my opinion that's the argument to return null for either parameters > which aren't an array or empty arrays simply because a first/last key > isn't present and null is the value to be returned for an undefined state. > I've tested this behavior with other array_* functions which are > 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:  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 > "var_dump(array_values('hello'));" > PHP Warning:  array_values() expects parameter 1 to be array, string > 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:  array_flip() expects parameter 1 to be array, null given > in Command line code on line 1 > NULL These return values are due to zend_parse_parameters() failures (i.e. the given types don't match the expected types), and it's customary to return NULL in this case (under strict typing an exception would be thrown instead). However, most functions signal other failures by returning FALSE, for instance: var_dump(array_search('foo', [])); // => bool(false) I would prefer, if these other functions would return NULL, though, but we can't change that for BC reasons. -- Christoph M. Becker