Re: Pseudo-objects (methods on arrays, strings, etc.)
| From: | David Muir | 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: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. Davidhi, On Wed, Jul 18, 2012 at 9:35 AM, Stas Malyshev <smalyshev@sugarcrm.com> wrote: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. -RasmusHi!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.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.