Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56704 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26618 invoked from network); 1 Dec 2011 17:35:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2011 17:35:05 -0000 Authentication-Results: pb1.pair.com header.from=ralph@ralphschindler.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=ralph@ralphschindler.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain ralphschindler.com from 209.85.213.170 cause and error) X-PHP-List-Original-Sender: ralph@ralphschindler.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:44141] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 24/F7-10027-8CAB7DE4 for ; Thu, 01 Dec 2011 12:35:05 -0500 Received: by yenq5 with SMTP id q5so2253846yen.29 for ; Thu, 01 Dec 2011 09:35:02 -0800 (PST) Received: by 10.236.181.36 with SMTP id k24mr13521024yhm.11.1322760902276; Thu, 01 Dec 2011 09:35:02 -0800 (PST) Received: from ralph-mac.local (ip174-73-14-247.no.no.cox.net. [174.73.14.247]) by mx.google.com with ESMTPS id x17sm16955221anj.18.2011.12.01.09.34.59 (version=SSLv3 cipher=OTHER); Thu, 01 Dec 2011 09:34:59 -0800 (PST) Message-ID: <4ED7BAC2.20805@ralphschindler.com> Date: Thu, 01 Dec 2011 11:34:58 -0600 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: Will Fitch CC: Nikita Popov , internals References: <4ED6713D.2050009@ralphschindler.com> <4ED67DCB.5090102@ralphschindler.com> <4ED68940.3050502@ralphschindler.com> <90D867E2-E6FB-481D-B57C-911E5FE6A418@gmail.com> In-Reply-To: <90D867E2-E6FB-481D-B57C-911E5FE6A418@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] 5.4's New De-referencing plus assignment From: ralph@ralphschindler.com (Ralph Schindler) I'll respond to all at once ;) On 11/30/11 1:58 PM, Will Fitch wrote: > If that's the case, then why not just add whatever $options is as a > parameter to your constructor. I'm not totally against this concept, > but this use is moot. I'm simply trying to find usefulness in the new feature of $x = (new Foo)->bar(); That's not useful to me. Mainly b/c if you don't get a handle on the object, what was the point in the first place? PHP already has a place for this in functions, static methods, AND if you're idea of OO programming is wrapping stateless functions in classes for "grouping" - in namespaces. On 11/30/11 1:13 PM, Nikita Popov wrote: > The plain (new Foo)->bar() syntax*is* useful for cases like (new > ReflectionClass($class))->implementsInterface('Foo'), where you need > only one single bit of information from a class. Sure that is useful.. Although that looks more to me like an edge case than my idea of how expression-dereferencing would work. Like I said above, if your object doesn't do much more than what a function would do, why not just file a feature request for Reflection to have a factory method on every class? ReflectionClass::factory($class)->implementsInterface('Foo'); // or fix is_subclass_of($classname, $interfacename) ;) Do we really want to encourage people to create objects for the purpose of calling a single method and tossing away the original object? You'd be better off using a function or a static method if that is what you want. Furthermore, if you want to chain methods, that is also dangerous since PHP cannot do type enforcement on return values. So, $instanceOfFooOrCoolResult = (new $foo)->do()->something()->cool(); needs to somehow guarantee that all methods of the type $foo will return $this. (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 not do it correctly in the first place".) The correct path here, IMO, would be to simply carry the expression result (since we're using '(' expr ')' out and allow dereferencing on whatever comes out of it. Here is a more contextual use case for my argument though: $rows = ($sql = new Sql)->from($table)->execute(); // i can interact with both $sql and $rows at this point. -ralph