Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59693 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16776 invoked from network); 11 Apr 2012 00:25:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Apr 2012 00:25:32 -0000 Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:33652] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 76/86-18401-B7FC48F4 for ; Tue, 10 Apr 2012 20:25:31 -0400 Received: by vbjk13 with SMTP id k13so317703vbj.29 for ; Tue, 10 Apr 2012 17:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:from:in-reply-to:mime-version:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=Nh0xbAdP27892PyNpvhPBuRWvuPVh1aFC/B7NUBqry4=; b=FmZiiJ8QPLzJdKlOSf7ib3gwP132mDXhCtdqgmjE6S5y0Z4+a1bzeXTJ8NDRJ5IIKh t4aPzXe77seAmYhgb1FYxmSSANsX7Qd3HGSuvwEgsoncwDOBFho0QluYWI4GMyhJopbd OBeNTd7YDifbuX+pHj0fqp0VahIOyZGHkMKLD5QULsAGl6ZELAYGfiUpVx8gYj8wUxSH GMQeJoFSUuiooLz54D+U0zwMdW24EFNuwsK0eKaASYSMK+giq/KBREjbgUCTFXS0aL0Z 1dm16mjEGgoh5aw3+BPAaLccfSURMtFfG5e4vvQA4pbrek+St+HMJZoUzBFzbcl2pKpp ZnBQ== Received: by 10.220.228.200 with SMTP id jf8mr6778918vcb.0.1334103928812; Tue, 10 Apr 2012 17:25:28 -0700 (PDT) References: In-Reply-To: Mime-Version: 1.0 (1.0) Date: Wed, 11 Apr 2012 08:25:26 +0800 Message-ID: <2853275242330628205@unknownmsgid> To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Allow non-variable arguments to empty() From: laruence@gmail.com (Xinchen Hui) Sent from my iPad =E5=9C=A8 2012-4-11=EF=BC=8C6:54=EF=BC=8CNikita Popov =E5=86=99=E9=81=93=EF=BC=9A > 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. +1 for this, but what about is set? They shou be consistent, :) Thanks > > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >