Re: substr/array_slice in []
| From: | Larry Garfield | Date: | Fri, 05 Oct 2007 01:05:30 +0000 |
| Subject: | Re: substr/array_slice in [] | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-32637@lists.php.net to get a copy of this message | ||
On Tuesday 02 October 2007, Alexey Zakhlestin wrote:
> On 10/1/07, Martin Alterisio <malterisio777@gmail.com> wrote:
> > Sorry to bother, I have a few questions on this matter.
> > How will this impact on the SPL ArrayAccess and related interfaces and
> > objects?
> > Will there be an interface to this functionality?
> > If so, how will ranges be passed through to this interface?
> > Will this be consistent with substr() and array_slice() if used with an
> > ArrayAccess implementation?
>
> I guess it can be made to work with current ArrayAccess, but result
> will be quite slow. (it will need to query requested elements
> one-by-one and recombine those in array)
>
> But adding another interface can solve the problem. Ranges can be
> passed exactly the way they are passed to [] operator
>
> public function rangeGet($start, $length);
> public function rangeSet($start, $length, array $data);
Here's the question I see. Right now, does an ArrayAccess object work with
array_slice()? If so, then [2, 5] syntax would be just some nice syntactic
sugar. If not, then it becomes a powerful new feature, and implementing it
on normal arrays and strings becomes just a matter of consistent syntax.
Personaly I kinda like it, but I know I'm not the one coding it. :-)
--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson