Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82549 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27237 invoked from network); 12 Feb 2015 18:56:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 18:56:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=tpunt@hotmail.co.uk; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tpunt@hotmail.co.uk; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.co.uk designates 157.55.1.169 as permitted sender) X-PHP-List-Original-Sender: tpunt@hotmail.co.uk X-Host-Fingerprint: 157.55.1.169 dub004-omc2s30.hotmail.com Received: from [157.55.1.169] ([157.55.1.169:58615] helo=DUB004-OMC2S30.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/00-27116-667FCD45 for ; Thu, 12 Feb 2015 13:56:39 -0500 Received: from DUB113-W52 ([157.55.1.137]) by DUB004-OMC2S30.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.22751); Thu, 12 Feb 2015 10:55:09 -0800 X-TMN: [DI3gw3NEiqJvWCWd2iJpYBfFoG37zrAd] X-Originating-Email: [tpunt@hotmail.co.uk] Message-ID: Content-Type: multipart/alternative; boundary="_1e23f9d4-0eeb-43d5-8b68-34ffde331f7e_" To: "internals@lists.php.net" Date: Thu, 12 Feb 2015 18:55:09 +0000 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 12 Feb 2015 18:55:09.0557 (UTC) FILETIME=[6C88A250:01D046F5] Subject: [DISCUSSION] Make empty() a Variadic From: tpunt@hotmail.co.uk (Thomas Punt) --_1e23f9d4-0eeb-43d5-8b68-34ffde331f7e_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello PHP Internals! I'd like to propose to make empty() a variadic=2C where if any arguments pa= ssed in are considered empty=2C then false is returned - otherwise return t= rue. My reasoning for wanting this feature is as follows:1)It's a common scenari= o to want to check multiple expressions for empty values. I frequently see = both of the following pieces of code in projects: #1 if (empty($a) ||= empty($b) || empty($c)) { // error here } #2 if (!empty($a) && !empty($b) && !empty($c)) { // all good!= } Both of the above examples could be shortened if empty() was made to accept= multiple arguments: #1 if (empty($a=2C $b=2C $c)) { // error = here } #2 if (!empty($a=2C $b=2C $c)) { // all good! } This creates more compact code that is (in my oppinion=2C at least) easier = to read. Some code from real-world projects that could benefit from this feature:Wor= dPress (one of many): https://github.com/WordPress/WordPress/blob/master/wp= -admin/includes/template.php#L1963OpenCart: https://github.com/opencart/ope= ncart/blob/45fc863fa068d82b5280890e6466a198faa54bff/upload/admin/controller= /openbay/ebay_profile.php#L128phpbb: https://github.com/phpbb/phpbb/blob/04= 0d451dcca9ae54d8f4b7bdd2f231033765a8f2/phpBB/phpbb/notification/method/jabb= er.php#L48 2)Users have brought up the want to pass in multiple arguments into empty()= before=2C such as:http://stackoverflow.com/questions/4993104/using-ifempty= -with-multiple-variables-phphttp://stackoverflow.com/questions/10950470/che= ck-if-multiple-strings-are-empty There have been solutions brought up by users to emulate a variadic empty= =2C like [1][2]=2C however for unset variables their solutions simply don't= work. So all in all=2C it seems like a simple feature to add for a short-hand not= ation of checking multiple expressions for emptiness (which seems like a co= mmon use-case for users). It has no BC implications and no real downsides (= at least I couldn't think of any). I have created a patch [3]=2C and if the= feedback is positive=2C then I'll create an RFC and submit a PR. Thanks=2CTom [1] http://stackoverflow.com/a/7798842/4530326[2] http://icoded.it/php-time= -saving-function-to-check-multiple-variables-for-empty-values/[3] https://g= ithub.com/tpunt/php-src/commit/66c563829775770507147872b98320cdfcb6c51c = = --_1e23f9d4-0eeb-43d5-8b68-34ffde331f7e_--