Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82550 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37964 invoked from network); 12 Feb 2015 19:21:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Feb 2015 19:21:44 -0000 Authentication-Results: pb1.pair.com header.from=kris.craig@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=kris.craig@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: kris.craig@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:63372] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/F1-27116-74DFCD45 for ; Thu, 12 Feb 2015 14:21:43 -0500 Received: by mail-ob0-f170.google.com with SMTP id va2so12076781obc.1 for ; Thu, 12 Feb 2015 11:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=zjfBGnl8APw+q9pgAsaC9oDXTb7LaYxIZ+K/8ckqftc=; b=DhfBgmr4NEWAx3bGM2RUqsJU6EqDtJKlcsBhlxi+RjDhKEczUkpavHIY9sRlag6Rtz m8KKTJ9rKVsheyrGKqUbOvnGq1cCjOkhZUxFYnHPZN88PV5UZ+UjfKd0Pg6ipktW8RFf ZiO4GcVV19pfB2I6tDAnsJgtD6vVhXqlFHv1ZZmtidzJuL5L7ACFeBxmFHJ0jjb5Mkc0 g7zbHIR3kNdaDcqc2Tnt0/bcV3h9+SUyXi71/3YOq72yZ8MpvyJMGPEIX4d43LJV4Qqc A0iJ1zXIAE7z0Ji8vqURbHa/Yop7Stif17Y7C2cDcDjr/R4vTC9OI47t1hk2JS843I0Q BT3A== MIME-Version: 1.0 X-Received: by 10.202.26.72 with SMTP id a69mr3538812oia.119.1423768900542; Thu, 12 Feb 2015 11:21:40 -0800 (PST) Received: by 10.202.65.136 with HTTP; Thu, 12 Feb 2015 11:21:40 -0800 (PST) In-Reply-To: References: Date: Thu, 12 Feb 2015 11:21:40 -0800 Message-ID: To: Thomas Punt Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113cf73e8f27a5050ee907f5 Subject: Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic From: kris.craig@gmail.com (Kris Craig) --001a113cf73e8f27a5050ee907f5 Content-Type: text/plain; charset=UTF-8 On Thu, Feb 12, 2015 at 10:55 AM, Thomas Punt wrote: > Hello PHP Internals! > I'd like to propose to make empty() a variadic, where if any arguments > passed in are considered empty, then false is returned - otherwise return > true. > My reasoning for wanting this feature is as follows:1)It's a common > scenario 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, $b, $c)) { // > error here } > #2 if (!empty($a, $b, $c)) { // all good! } > This creates more compact code that is (in my oppinion, at least) easier > to read. > Some code from real-world projects that could benefit from this > feature:WordPress (one of many): > https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/template.php#L1963OpenCart: > > https://github.com/opencart/opencart/blob/45fc863fa068d82b5280890e6466a198faa54bff/upload/admin/controller/openbay/ebay_profile.php#L128phpbb: > > https://github.com/phpbb/phpbb/blob/040d451dcca9ae54d8f4b7bdd2f231033765a8f2/phpBB/phpbb/notification/method/jabber.php#L48 > > 2)Users have brought up the want to pass in multiple arguments into > empty() before, such as: > http://stackoverflow.com/questions/4993104/using-ifempty-with-multiple-variables-phphttp://stackoverflow.com/questions/10950470/check-if-multiple-strings-are-empty > There have been solutions brought up by users to emulate a variadic empty, > like [1][2], however for unset variables their solutions simply don't work. > > So all in all, it seems like a simple feature to add for a short-hand > notation of checking multiple expressions for emptiness (which seems like a > common 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], and if the > feedback is positive, then I'll create an RFC and submit a PR. > Thanks,Tom > [1] http://stackoverflow.com/a/7798842/4530326[2] > http://icoded.it/php-time-saving-function-to-check-multiple-variables-for-empty-values/[3] > https://github.com/tpunt/php-src/commit/66c563829775770507147872b98320cdfcb6c51c > I'd say go ahead and draft an RFC with all the details of your proposed change, then we can discuss and vote on it. On the surface, it looks like a useful feature that wouldn't break any existing code. --Kris --001a113cf73e8f27a5050ee907f5--