Re: Pseudo-objects (methods on arrays, strings, etc.)

From: Date: Thu, 19 Jul 2012 00:10:56 +0000
Subject: Re: Pseudo-objects (methods on arrays, strings, etc.)
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-61451@lists.php.net to get a copy of this message
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 <smalyshev@sugarcrm.com> 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. David

« previous php.internals (#61451) next »