Re: Adding a more logical string slicing function to PHP
| From: | Dan Birken | Date: | Thu, 31 Mar 2011 18:40:21 +0000 |
| Subject: | Re: Adding a more logical string slicing function to PHP | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51779@lists.php.net to get a copy of this message | ||
On a somewhat related note (and going back a little to my original patch),
languages like python and ruby allow slicing on array/string objects with
$string_or_array[start:end] syntax. I think this would be really useful
syntax in PHP as well (and would of course make the initial patch I
submitted obsolete). The one thing I was hesitant about with my patch was
polluting the global function space for PHP, and I think adding new and
specific syntax to provide these things is much better.
I have no idea how feasible it is given PHP's internal structure, but if it
was possible I would be glad to try to write a patch for it.
-Dan
On Thu, Mar 31, 2011 at 11:10 AM, Rasmus Lerdorf <rasmus@lerdorf.com> wrote:
> On 03/31/2011 10:58 AM, Martin Scotta wrote:
> > I think it's time to stop thinking in terms of "functions" and move
> > forward to "abstractions"
> >
> > $s1 = 'string';
> > $s1->contains($s2);
> >
> > $s1->indexOf($s2) === strpos($s1, $s2);
> >
> > Why can't the strings be exposed as pseudo-objects ? users can choose to
> > use them as a regular strings or by calling methods on it.
>
> This is actually something I have been toying with a bit. Adding the
> ability to call methods on both strings and arrays. I still don't like
> the idea of making them real objects as the overhead and the amount of
> code that would need to be changed in the core and in every extension is
> daunting. Anybody out there have a patch along these lines?
>
> -Rasmus
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>