Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59879 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79504 invoked from network); 13 Apr 2012 13:00:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Apr 2012 13:00:38 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@googlemail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@googlemail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:54167] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 41/48-35770-573288F4 for ; Fri, 13 Apr 2012 09:00:37 -0400 Received: by lbbgf7 with SMTP id gf7so2435484lbb.29 for ; Fri, 13 Apr 2012 06:00:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=e7Ofxp0RKMIeFLstVGVU2QZtjtHMI6qwEv3WCdItOh4=; b=MUpx+VGa0f49eT5YYgiFUfqNpVfNjspNKJcTzmiE2skpEDfetwKzriNbhDbLZh2ZXv G23FhWMaHMlGFTtldjnkdDOHNz1+L//g7eDNFEh1pUoxlNwRst7bj9FsOwRug8wMFTyu jaKfXi11TM+rW2rmWsCWXXlnOIwLPs6tWBvmLINBtZt4sr9W9W8GAtxDjFU9QhnL2ZBv YHXIr/Ky7BHTTZ0qnVFyA25apE+mbo+1Q0yI7NgEOG8j6j0Hba8tUnqgGGEdycGsRpqE 37DNR7+pV3WHn7Nlp9XXNNrD8axqdzpphTVCGSHxZYUZbkZM8ivYjYvhU4+EnvrAs4BU y95g== MIME-Version: 1.0 Received: by 10.152.103.134 with SMTP id fw6mr1388771lab.20.1334322034581; Fri, 13 Apr 2012 06:00:34 -0700 (PDT) Received: by 10.152.127.68 with HTTP; Fri, 13 Apr 2012 06:00:34 -0700 (PDT) In-Reply-To: References: <1334271932.4609.161.camel@guybrush> Date: Fri, 13 Apr 2012 15:00:34 +0200 Message-ID: To: Pal Konyves Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Allow non-variable arguments to empty() From: nikita.ppv@googlemail.com (Nikita Popov) On Fri, Apr 13, 2012 at 11:37 AM, Pal Konyves wrote: > I don't see the point of empty( function() ). > > You tipically use empty on values that holds information you want to use > later in the program flow (a string, an integer). That means you'd better > extract it to a variable because you want to avoid calling twice a function > that provides this value. You don't always need the value. Browsing around Google it seems that one of the most common source of the function call in write context error is people trying to do if(empty(trim($xyz)). You don't necessarily need the result of trim($xyz), so it's reasonable not to save it into a temporary variable. Another example for example would be a function like this: public function isValid() { if (...) { $this->addError('xyz'); } if (...) { $this->addError('abc'); } if (...) { $this->addError('foo'); } if (...) { $this->addError('bar'); } return empty($this->getErrors()); } Furthermore you don't necessarily have to throw the return value away. For example I commonly write code like this: if (null === $result = $this->foo()) { throw new Exception(...); } $result->doSomething(); You can do something similar with empty(): if (empty($values = $this->getValues()) { return; } $this->doSomethingWith($values); I know, not everyone likes that kind of coding style, but I think it has it's uses. Nikita