Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83391 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23236 invoked from network); 21 Feb 2015 15:04:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Feb 2015 15:04:09 -0000 Authentication-Results: pb1.pair.com header.from=tpunt@hotmail.co.uk; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tpunt@hotmail.co.uk; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.co.uk designates 157.55.1.160 as permitted sender) X-PHP-List-Original-Sender: tpunt@hotmail.co.uk X-Host-Fingerprint: 157.55.1.160 dub004-omc2s21.hotmail.com Received: from [157.55.1.160] ([157.55.1.160:50098] helo=DUB004-OMC2S21.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 55/07-08895-66E98E45 for ; Sat, 21 Feb 2015 10:04:08 -0500 Received: from DUB113-W104 ([157.55.1.137]) by DUB004-OMC2S21.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.22751); Sat, 21 Feb 2015 07:04:04 -0800 X-TMN: [r4tD357kLkhcHps7daosn3DZhfMM2y1t] X-Originating-Email: [tpunt@hotmail.co.uk] Message-ID: Content-Type: multipart/alternative; boundary="_512d3986-24c9-46af-8b42-5592cbd8b942_" To: Markus Fischer , "internals@lists.php.net" Date: Sat, 21 Feb 2015 15:04:03 +0000 Importance: Normal In-Reply-To: References: ,<54E831BA.80609@fischer.name>, MIME-Version: 1.0 X-OriginalArrivalTime: 21 Feb 2015 15:04:04.0008 (UTC) FILETIME=[A1BD8280:01D04DE7] Subject: RE: [PHP-DEV] [RFC] Make empty() a Variadic From: tpunt@hotmail.co.uk (Thomas Punt) --_512d3986-24c9-46af-8b42-5592cbd8b942_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable // Sorry=2C having email formatting problems still. Hopefully this one will= be more legible. Hey Markus=2C > From the RFC: > > This behaviour seems to be the most prevalent usage of multiple empty > checks in a condition=2C therefore benefitting the most end users. >=20 > Here I disagree. >=20 > I would have assumed from the start that empty() would only return true > if *all* of the entries are empty=2C i.e. AND things together. >=20 > If we enable variable arity then it will join the group of function > where no user sanely can remember if in_array/etc. take the > needle/haystack first or second argument. I.e. whether it will OR or AND > all arguments. My rationale for this is that empty() performs an inverse check to isset()= =2C so I feel it should have inversed behaviour too (i.e. logically OR'ing = its arguments together instead of logically AND'ing them together). To quot= e what Andrea wrote in the pre-RFC discussion thread: > From: Andrea Faulds > Date: Fri Feb 13 06:31:38 2015 > > So !empty($a=2C $b=2C $c) would work similarly to isset($a=2C $b=2C $c)= =2C and similarly=2C !isset($a=2C $b=2C $c) would work similarly to empty($= a=2C $b=2C $c). This means that we keep the (rough) equivalence of `empty() =3D=3D !isset()= ` - which is true since a variable that is not set or is null is going to b= e a falsy value=2C so both the `empty()` and `!isset()` expressions will re= turn TRUE. Likewise for `!empty() =3D=3D isset()` - if an argument does not= have a falsy value=2C then empty() will return FALSE. isset() will return = TRUE on that same value since a variable cannot be truthy and either not se= t or null. Now=2C if we changed the semantics to how you're seeing them=2C then we wou= ld have the following: From http://php.net/manual/en/function.isset.php : > "If multiple parameters are supplied then isset() will return TRUE > only if all of the parameters are set. Evaluation goes from left to > right and stops as soon as an unset variable is encountered." >=20 > But this is an AND: "... if all ... are set": >=20 > "isset($a=2C$b)" behaves like "isset($a) && isset($b)" >=20 > IMHO this absolutely violates your POLA because as I said this is also > how I would assume empty() with variable arguments would work: Only > return true if all are true. If we had an empty-based function that did not perform a reverse check to i= sset()=2C such as `not_empty()`=2C then I'd say it should behave like isset= (): var_dump(not_empty($a=2C $b=2C $c) =3D=3D=3D isset($a=2C $b=2C $c))=3B // t= rue But because this is not the case for empty()=2C I'd say it would be confusi= ng for it to act the same way isset() does. > My personal opinion is that any attempt to change this is ill-fated > because people will no be able to memoize the exact usage of it because > it would mean different things to different people and would just add > more confusion. My aim is to make empty()'s behaviour intuitive so that users don't have to= memorise its semantics. > - Markus Thanks for your input Markus and I hope you can better see where I am comin= g from with my current RFC :) -Tom = --_512d3986-24c9-46af-8b42-5592cbd8b942_--