Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46773 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85146 invoked from network); 18 Jan 2010 07:49:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jan 2010 07:49:28 -0000 Authentication-Results: pb1.pair.com header.from=lars.schultz@toolpark.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lars.schultz@toolpark.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain toolpark.com from 195.49.42.12 cause and error) X-PHP-List-Original-Sender: lars.schultz@toolpark.com X-Host-Fingerprint: 195.49.42.12 mail1.screenlight.ch Received: from [195.49.42.12] ([195.49.42.12:58236] helo=mail1.screenlight.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/D8-20170-682145B4 for ; Mon, 18 Jan 2010 02:49:28 -0500 Received: from [127.0.0.1] ([84.73.218.162]) (authenticated user lars.schultz@toolpark.com) by mail1.screenlight.ch (Kerio MailServer 6.7.0 patch 1); Mon, 18 Jan 2010 08:49:18 +0100 Message-ID: <4B54127C.5020107@toolpark.com> Date: Mon, 18 Jan 2010 08:49:16 +0100 User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Richard Lynch CC: internals@lists.php.net References: <4B4DCC64.3030703@easyflirt.com> <1527.98.193.1263709030.squirrel@www.l-i-e.com> In-Reply-To: <1527.98.193.1263709030.squirrel@www.l-i-e.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 100117-1, 17.01.2010), Outbound message X-Antivirus-Status: Clean Subject: Re: [PHP-DEV] Inconsistency redesign From: lars.schultz@toolpark.com (Lars Schultz) I love empty, because its fast and compact. checking an array for a boolean value when a key does not exist, like here: A: if ( empty($foo['x']) ) echo 'no x'; this does not throw a notice that 'x' does not exist and is the fastest variant compared to these two, even if 'x' exists. I especially like the lack of ! to negate the condition. B: if ( !$foo['x'] ) echo 'no x'; this is simple but not faster in any case and throws a notice if it is not set. C: if ( !isset($foo['x']) || !$foo['x'] ) echo 'no x'; this is very correct but clumsy and slower than empty() in any case as far as consistency is concerned I think that it behaves the same as B & C...but I may be wrong:) PHP always had a canny behaviour when converting any value to a boolean, but when I got used to it and escaped the common pitfalls, I started liking it for it's compactness and it's naturalness. of course, an empty string is empty(), an empty array is empty() and zero is empty()...naturally. The atypical behaviour that it throws a fatal error when using it like this: if ( empty(bar()) ) probably stems from the fact that it's really fast;) it's not very bad though...