Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59682 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99380 invoked from network); 10 Apr 2012 23:13:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Apr 2012 23:13:04 -0000 Authentication-Results: pb1.pair.com header.from=jelle.zijlstra@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jelle.zijlstra@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: jelle.zijlstra@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:42476] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 41/F2-18401-E7EB48F4 for ; Tue, 10 Apr 2012 19:13:03 -0400 Received: by werh12 with SMTP id h12so235836wer.29 for ; Tue, 10 Apr 2012 16:12:59 -0700 (PDT) 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:cc :content-type; bh=VOrrE8QJgRy/573wH0HfR7+qzHe/wRYHyxPwLrA7Lfk=; b=B7CQRe4Zka7XuSE/1roSGVBMeg7SzeUEER50hcZ9VIo6AFMwy1p+zwLUtW49e4U6Lq Y1VWNDbm7A+Q75sUz5NpZ9U30BX6BtRnY/wk4ac16ocbj/WCnDFxlSS/3SE5RJJX2eqx F0kx8QCLDsFK7fUounyevTHcoFL2R6O7yD+FLTh+qmM+LN7UQdqIN3IH91ZZb2ZVx/Mc QRbdw5F8i7dE0KsO5CjmbcTPy5jGsIUX5T5YS9r4TPetirAKbQX9bWjjw/emPF2hgide esE57GSMHkr6S8rtOhY7yJbPwe03idMTpTrdT1PPjXX1kBw/WPOeR/c8KT2vdPcePUoa nwrw== MIME-Version: 1.0 Received: by 10.180.88.67 with SMTP id be3mr10843860wib.20.1334099579289; Tue, 10 Apr 2012 16:12:59 -0700 (PDT) Received: by 10.216.26.67 with HTTP; Tue, 10 Apr 2012 16:12:59 -0700 (PDT) In-Reply-To: References: Date: Tue, 10 Apr 2012 19:12:59 -0400 Message-ID: Cc: PHP internals Content-Type: multipart/alternative; boundary=f46d0444814784c12204bd5b4311 Subject: Re: [PHP-DEV] Allow non-variable arguments to empty() From: jelle.zijlstra@gmail.com (Jelle Zijlstra) --f46d0444814784c12204bd5b4311 Content-Type: text/plain; charset=ISO-8859-1 2012/4/10 Nikita Popov > Hey internals! > > Currently the empty() language construct only works on variables. You > can write if (empty($array)) but not empty if (empty(getSomeArray()). > > The original reason for this restriction probably is that - in a way - > it "doesn't make sense" to pass anything but a variable to empty() as > you could just use the ! operator in this case. if > (empty(getSomeArray())) is logically equivalent to if > (!getSomeArray()). > > I'd like to propose to change empty() to accept arbitrary expressions. > > The reason is simple: Even though it is possible to write if > (!getSomeArray()) with the same effect, if (empty(getSomeArray())) > reads much nicer. !getSomeArray() to me somehow implies that > getSomeArray() may return a bool(false) or something like that. On the > other hand empty(getSomeArray()) seems naturally fit for checking for > empty arrays. > > Another reason is that currently you get a very obscure error message > if you try to use empty() on a function return value: "Can't use > function return value in write context". Aha. Where did I try to write > to the return value?! > > So, what do you think? > > I think this is a useful simplification of the language, removing an unnecessary exception. Would it also make sense to make empty() into a library function instead of a language construct? That would not result in any BC break as far as I can see, but would allow some things that are currently impossible (e.g., a method called "empty") and further simplify the language. > Nikita > > PS: The patch is trivial: https://gist.github.com/2355274 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d0444814784c12204bd5b4311--