Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61452 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98347 invoked from network); 19 Jul 2012 00:16:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 00:16:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.160.42 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:56577] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E7/B0-22428-9E157005 for ; Wed, 18 Jul 2012 20:16:42 -0400 Received: by pbbrp12 with SMTP id rp12so3700128pbb.29 for ; Wed, 18 Jul 2012 17:16:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=HLbJINko4t0nwIn35xwLMjATX4IDbE/UbCeIcBzyvkc=; b=k1HJ358gBCUPqsByIkuFS1h3lCePd72Ov9w8t59fHu4y+1p3qTyjymUyhCkwvR/TuV M7a+8X/+Xc38ma7FVgrtRsRNgsy70Qis4Gj5ULi8MPLtsizmlv2bU1O3VsPAegcQOWX1 R9+niLpAGSRIVM1DjERcxyiiRXU8UaRFwltRFxgiiG1rl+vS18tW2gkyn1RMlBgix9vo 6Yp9825sYEEgIMPckjrymO5Hf5C9R1ZVFbzMldLvPvfPEXhn9b5W95m8Y1uDz9Brbizu ZPpkpyINTT+oKDNNQ3lKIAdB+6crKdSelnwqzF464hx4WUZLWdq/OMsTjK9Kj6beOnAq 2C/w== Received: by 10.68.202.136 with SMTP id ki8mr360626pbc.65.1342656998906; Wed, 18 Jul 2012 17:16:38 -0700 (PDT) Received: from [10.10.27.97] ([67.23.204.5]) by mx.google.com with ESMTPS id ms9sm560484pbb.43.2012.07.18.17.16.37 (version=SSLv3 cipher=OTHER); Wed, 18 Jul 2012 17:16:37 -0700 (PDT) Message-ID: <500751DF.2080309@lerdorf.com> Date: Wed, 18 Jul 2012 17:16:31 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: David Muir CC: Pierre Joye , Stas Malyshev , internals References: <50059AF8.5050805@sugarcrm.com> <5005CB58.2020601@sugarcrm.com> <50066724.6050901@sugarcrm.com> <50070538.10206@lerdorf.com> <50075090.3020003@gmail.com> In-Reply-To: <50075090.3020003@gmail.com> X-Enigmail-Version: 1.4.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnzwUmJkZ2sOSF+jjKuEzV2hG8HNLOnRNZ+UTzeqHBOurgvjf9c3qQ/3d4hYgqJgovvSvrV Subject: Re: [PHP-DEV] Pseudo-objects (methods on arrays, strings, etc.) From: rasmus@lerdorf.com (Rasmus Lerdorf) 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