Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61454 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5265 invoked from network); 19 Jul 2012 02:00:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 02:00:22 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:56740] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3B/A1-22428-53A67005 for ; Wed, 18 Jul 2012 22:00:22 -0400 Received: by lbgc1 with SMTP id c1so3338973lbg.29 for ; Wed, 18 Jul 2012 19:00:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=gaH4S0QzR/GFm7S/4Xbr45CGJn4qGSmddnb4pcbEQbc=; b=r1H5TiD/GWIXp/0bArgOvILHlIdUk5hXzDPqV0WGahQ+7cHUl9k+E0fhtHoeMPSl3b O1Hh9Ll4X/pqjtzqgT9QsD2ReGjmxtrcQQNewoVtA1r43W8W4/LCITBgXhRgt2oSnXzD WBRVmCDflm9wduJSr7vhKb4tv4V0RwvRQbafVkIqyu2hCF7esrUrVpG4XtYMui7veJgx hUEhvxNX0vwcu1v5BnbiDtL8t7BAIkPHfE9ygjc9lzFQkvgjNuynwW7CLjBb+HP10jQK JQHIOq28QTSFGAqIOJC2HcY4WFcWyY6JylzeMzRnn24KUJkaeTUxX23j8O6V7IWMXoC/ v0Aw== MIME-Version: 1.0 Received: by 10.152.104.44 with SMTP id gb12mr5940961lab.29.1342663217993; Wed, 18 Jul 2012 19:00:17 -0700 (PDT) Received: by 10.112.113.138 with HTTP; Wed, 18 Jul 2012 19:00:17 -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: Wed, 18 Jul 2012 20:00:17 -0600 Message-ID: To: Rasmus Lerdorf Cc: David Muir , Pierre Joye , Stas Malyshev , internals Content-Type: multipart/alternative; boundary=f46d04088ef52957cb04c52524d9 Subject: Re: [PHP-DEV] Pseudo-objects (methods on arrays, strings, etc.) From: morrison.levi@gmail.com (Levi Morrison) --f46d04088ef52957cb04c52524d9 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jul 18, 2012 at 6:16 PM, 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 > > Really? Good to know . . . --f46d04088ef52957cb04c52524d9--