Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61478 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60031 invoked from network); 19 Jul 2012 11:45:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 11:45:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajfweb@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajfweb@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: ajfweb@googlemail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:52222] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 97/96-25752-673F7005 for ; Thu, 19 Jul 2012 07:45:58 -0400 Received: by wibhn17 with SMTP id hn17so4861876wib.11 for ; Thu, 19 Jul 2012 04:45:56 -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=QjY7mPcGbcNKt7wFCBdxpwfnPCnkwKMzMjGY7coSs3E=; b=R9fpulrJ+1MbeGex+FyWkgWMyNHSnXSMmjTyoIRQSuv8XY9l/vOXdGfbenino6u68y Q87w6MQacniYJzEt7doQTnOtQ1JgiHqzlsQE9T8jmSHsGU6GwqeaNoxMmUlq56h89MP8 KnjMWMhKI+cV3TqjuzCFTqye+79NJMRTjG6nsOjllFhUxw2KbjIXTIyOwDAnVJX6sHQl MyT1CRzwOoi7t+62f/JmQjvhDFhiqrRGjYVDhS5dUKNI8VL6n6aayYvs2G4sjL/L2lKK w6oxT1iGG/SWNaphjOKasp7dgPWSPY/6aQveyniHz2Ytgi5LQYfQs5ogs8sycebfxGCa 6UrQ== MIME-Version: 1.0 Received: by 10.180.92.129 with SMTP id cm1mr15528586wib.10.1342698355203; Thu, 19 Jul 2012 04:45:55 -0700 (PDT) Received: by 10.216.160.16 with HTTP; Thu, 19 Jul 2012 04:45:54 -0700 (PDT) Received: by 10.216.160.16 with HTTP; Thu, 19 Jul 2012 04:45:54 -0700 (PDT) In-Reply-To: <500751DF.2080309@lerdorf.com> References: <50059AF8.5050805@sugarcrm.com> <5005CB58.2020601@sugarcrm.com> <50066724.6050901@sugarcrm.com> <50070538.10206@lerdorf.com> <50075090.3020003@gmail.com> <500751DF.2080309@lerdorf.com> Date: Thu, 19 Jul 2012 12:45:54 +0100 Message-ID: To: Rasmus Lerdorf Cc: Pierre Joye , Stas Malyshev , David Muir , internals Content-Type: multipart/alternative; boundary=f46d043c7d14809ede04c52d5219 Subject: Re: [PHP-DEV] Pseudo-objects (methods on arrays, strings, etc.) From: ajfweb@googlemail.com (Andrew Faulds) --f46d043c7d14809ede04c52d5219 Content-Type: text/plain; charset=UTF-8 Right, because I've never got them the wrong way round, that is completely logical, and this syntax makes it much harder. On Jul 19, 2012 1:17 AM, "Rasmus Lerdorf" wrote: > On 07/18/2012 05:10 PM, David Muir wrote: > > On 19/07/12 04:49, Rasmus Lerdorf wrote: > >> On 07/18/2012 01:02 AM, Pierre Joye wrote: > >>> hi, > >>> > >>> On Wed, Jul 18, 2012 at 9:35 AM, Stas Malyshev > >>> wrote: > >>>> Hi! > >>>> > >>>>> See the other answers, clear APIs, no more argument mess, cleanness. > >>>> Cleanness has nothing to do with pseudo-objects.You don't have to use > >>>> -> to have clean APIs, and using -> doesn't automatically make your > >>>> APIs > >>>> clean. > >>> I really do not want to have a semantic discussion here. > >>> > >>> This syntax is sexy, allows us to clean our APIs, and is amazingly > >>> handy. > >> This makes no sense to me either. How does it let us clean the APIs? Can > >> you give an example? I have one: > >> > >> $a = -5; > >> $b = "-5"; > >> > >> echo $a->abs(); // Outputs 5 > >> echo $b->abs(); // should still output 5 > >> > >> What has been cleaned here over: > >> > >> echo abs($a); > >> echo abs($b); > >> > >> other than being 2 characters longer to type? It's not like you can > >> remove abs() from the string pseudo-object, so you are essentially just > >> taking all the functions in the global namespace and attaching them as a > >> method to every pseudo-object. Is that clean? > >> > >> I think there is something we can do around this, but an argument of "it > >> is sexy and clean" needs to be backed up with some actual implementation > >> details that make sense. > >> > >> -Rasmus > >> > > > > Which is the needle, and which is the haystack? > > $pos = strpos($string, 'a'); > > $pos = strpos('a', $string); > > > > vs > > $pos = $string->pos('a'); > > $pos = 'a'->pos($string); > > > > I'm not proposing to use pos() as the method name, just showing an > > example that this syntax can be cleaner. > > Or you could simply remember that it is always haystack,needle for > strings and needle,haystack for arrays. Not that complicated. > > -Rasmus > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d043c7d14809ede04c52d5219--