Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59684 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2121 invoked from network); 10 Apr 2012 23:15:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Apr 2012 23:15:22 -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 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: kris.craig@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:45805] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/83-18401-90FB48F4 for ; Tue, 10 Apr 2012 19:15:22 -0400 Received: by werh12 with SMTP id h12so236745wer.29 for ; Tue, 10 Apr 2012 16:15:19 -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:to :cc:content-type; bh=iRWWb19K3WWxY3wQ7RylCOYXK0LgDSP/Vl8Qpnu4i/w=; b=gHZFJeQuaTOy0uZbSFbihzkhwmaC5iLhr+sBDvwowPi6dX6A5ZS3V9vth9fIngksya m5uW8dmrAkc/4YzwlpJ7joglYo5s5/NujL7LM6XIWANJ5d6nyfLmuivgBxiZeeCofVYl 5JMop8IAnpkVKhEzmT3mtVHOxrAjry+PiSG79qJbcIIKfCQOCe3KFSZCkf/5QahOP2uP RYI+d+E/O7iQfqtqcQYfIaTNMKgx3PQgYAhvgNr4j4z7aMrJz4+PsrqxJ005jx+jA8B3 XDeqLCnqPAX6c+CVknwNJQCcFpszxc7IVnmQwRs54DhOvRUPZVr+Ir4oZQkKQ+AvW3Rv HQIg== MIME-Version: 1.0 Received: by 10.180.95.197 with SMTP id dm5mr1270106wib.20.1334099719034; Tue, 10 Apr 2012 16:15:19 -0700 (PDT) Received: by 10.223.79.67 with HTTP; Tue, 10 Apr 2012 16:15:18 -0700 (PDT) In-Reply-To: References: Date: Tue, 10 Apr 2012 16:15:18 -0700 Message-ID: To: Jelle Zijlstra Cc: PHP internals Content-Type: multipart/alternative; boundary=f46d04447f47d9168904bd5b4ba4 Subject: Re: [PHP-DEV] Allow non-variable arguments to empty() From: kris.craig@gmail.com (Kris Craig) --f46d04447f47d9168904bd5b4ba4 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Apr 10, 2012 at 4:12 PM, Jelle Zijlstra wrote: > 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 > > > > > +1 on this. Could you draft this into an RFC for us? --Kris --f46d04447f47d9168904bd5b4ba4--