Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59681 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97236 invoked from network); 10 Apr 2012 22:53:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Apr 2012 22:53:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@googlemail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:34061] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/92-18401-5F9B48F4 for ; Tue, 10 Apr 2012 18:53:42 -0400 Received: by lahl5 with SMTP id l5so268877lah.29 for ; Tue, 10 Apr 2012 15:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=i4ECEBlV6TXhY0/3qq5ch2zqEQFsAi99bxuQTLvXF1M=; b=H1Rf1v03D87V6GtcNKjQSCne9OOZMARSlhKeX4nLuOKCa8GHlrNwM/3rx/W5bRzZm3 Z3QZPL5vBWE6hNphQjpyOC8zoxjBoeEIR4v5G3118J5/BS2JulwmDodX/zzfzC4zNwsb DYpFq8TN1p2nrYd6QKDBAtkjx8WqP/FWx0xpxHRLQt91+VBHpy0HYbkbPsySqU3jDo+6 JPnf1FMLMiAWsmvy/ErwAwtLJ71GunvtKRxobyDknI2N9GCcFfYhWcEg7uzs2U8fWgIv Ig46aBy3t9sFIg4s6xVGpEqLKShdaV4SjKWuFnbCVpVgRAqsh2Li5FtZo8QCJ2uxUv89 k+Ww== MIME-Version: 1.0 Received: by 10.112.38.68 with SMTP id e4mr1969626lbk.38.1334098418309; Tue, 10 Apr 2012 15:53:38 -0700 (PDT) Received: by 10.152.127.68 with HTTP; Tue, 10 Apr 2012 15:53:38 -0700 (PDT) Date: Wed, 11 Apr 2012 00:53:38 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Allow non-variable arguments to empty() From: nikita.ppv@googlemail.com (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? Nikita PS: The patch is trivial: https://gist.github.com/2355274