Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56729 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48797 invoked from network); 2 Dec 2011 17:30:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Dec 2011 17:30:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:40912] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/25-16911-F2B09DE4 for ; Fri, 02 Dec 2011 12:30:24 -0500 Received: by qcsc1 with SMTP id c1so405670qcs.29 for ; Fri, 02 Dec 2011 09:30:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=CLf1dH0UCrv1LjRZ1xq2FNq11W+4pM0IMV5LOw2RuN0=; b=KhpF431n/OmlG1bL6kgPWWaadoAmkBdK6PnNxgshfS3mPkF+cNCAk8lPW1LTa/pG32 11qxENSQMBN32XkGF8aOArGJOQIwURK5t/MuwYw4tvSjRdLnzmz0KVwN64IkFk6DJyhm QzKfEJ0cyA4p5qQQQKr8rpYk0gsLiA2/IK298= MIME-Version: 1.0 Received: by 10.229.217.201 with SMTP id hn9mr694028qcb.0.1322847021433; Fri, 02 Dec 2011 09:30:21 -0800 (PST) Received: by 10.229.225.201 with HTTP; Fri, 2 Dec 2011 09:30:21 -0800 (PST) In-Reply-To: <9B.03.16911.EB109DE4@pb1.pair.com> References: <4ED6713D.2050009@ralphschindler.com> <4ED67DCB.5090102@ralphschindler.com> <4ED68940.3050502@ralphschindler.com> <90D867E2-E6FB-481D-B57C-911E5FE6A418@gmail.com> <4ED7BAC2.20805@ralphschindler.com> <9B.03.16911.EB109DE4@pb1.pair.com> Date: Fri, 2 Dec 2011 12:30:21 -0500 Message-ID: To: "Matthew Weier O'Phinney" Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] 5.4's New De-referencing plus assignment From: ircmaxell@gmail.com (Anthony Ferrara) > =A0 =A0if (!(($validator =3D new SomeValidator())->isValid($value))) { If you wanted to get into the whole "readable code" thoughts, that's a fubar mess. However, I can see your point and your usecase. Then again, if we're talking about OO design, that's bad in general since it creates a tight coupling to the validator class and is not polymorphic. I guess my thought is that I would be fine with it as long as it can accept reasonably arbitrary expressions... On Fri, Dec 2, 2011 at 11:50 AM, Matthew Weier O'Phinney wrote: > On 2011-12-01, Anthony Ferrara wrote: >> On Thu, Dec 1, 2011 at 12:34 PM, Ralph Schindler >> wrote: > >> > needs to somehow guarantee that all methods of the type $foo will retu= rn >> > $this. =A0(BTW, this is not an argument for my feature as much as its = an >> > argument as much as its one for "if we're going to do something, why n= ot do >> > it correctly in the first place".) =A0The correct path here, IMO, woul= d be to >> > simply carry the expression result (since we're using '(' expr ')' out= and >> > allow dereferencing on whatever comes out of it. >> > >> >> I would argue though that your syntax is completely possible today: >> >> $foo =3D new Foo; >> $foo->bar(); >> >> What's the reason to put that in a single line? =A0Aside from terseness, >> is there any other benefit? =A0With the new dereference, one benefit is >> that no variable is populated when none is needed. =A0But in your case, >> you need both variables... > > Here's another example. > > We have validator classes. Typically, you call isValid() to see if a > value validates. If it does, you have no more use for the validator. If > it _doesn't_, however, you'll want to get the error messages. I could > see the following as being a nice, succinct way to use validators: > > =A0 =A0if (!(($validator =3D new SomeValidator())->isValid($value))) { > =A0 =A0 =A0 =A0// Validation failed, get messages... > =A0 =A0 =A0 =A0$view->assign('errors' =3D> $validator->getMessages()); > =A0 =A0 =A0 =A0return $view->render('error'); > =A0 =A0} > =A0 =A0// validation passed, do something... > > Yes, this could be written as follows: > > =A0 =A0$validator =3D new SomeValidator(); > =A0 =A0if (!$validator->isValid($value)) { > =A0 =A0 =A0 =A0// ... > =A0 =A0} > =A0 =A0// ... > > However, I can see some folks not really wanting that variable > declaration if they won't be using it outside the conditional. > > -- > Matthew Weier O'Phinney > Project Lead =A0 =A0 =A0 =A0 =A0 =A0| matthew@zend.com > Zend Framework =A0 =A0 =A0 =A0 =A0| http://framework.zend.com/ > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >