RFC array functions

php.internals

Marcus Börger

20 years ago
Hello internals, i'd like to add two array functions: - bool array_has_more(array $array) checks whether $array has more elements after current position or if array is at last position, preferable working inside foreach - bool array(array $array) cehcks whether arra position is valid (e.g. like "key($array) !== NULL") Any comments? Best regards, Marcus

Pierre Joye

20 years ago
On 5/27/06, Marcus Boerger <helly@php.net> wrote:
> Hello internals, > > i'd like to add two array functions: > > - bool array_has_more(array $array) > > checks whether $array has more elements after current position or > if array is at last position, preferable working inside foreach
a big +1 :)
> - bool array(array $array) > > cehcks whether arra position is valid (e.g. like "key($array) !== NULL")
I don't understand this one. --Pierre

Matthew Charles Kavanagh

20 years ago
Pierre wrote:
> On 5/27/06, Marcus Boerger <helly@php.net> wrote: >> - bool array(array $array) >> >> cehcks whether arra position is valid (e.g. like "key($array) !== >> NULL") > > I don't understand this one. >
I think you have to listen to psychedelic music and take a hit of LSD first.

Marcus Börger

20 years ago
Hello Matthew, Saturday, May 27, 2006, 11:36:16 PM, you wrote:
> Pierre wrote: >> On 5/27/06, Marcus Boerger <helly@php.net> wrote: >>> - bool array(array $array) >>> >>> cehcks whether arra position is valid (e.g. like "key($array) !== >>> NULL") >> >> I don't understand this one. >>
> I think you have to listen to psychedelic music and take a hit of LSD first.
Actually the point is that you cannot simply do stuff like "while(key($array))". And "while(key($array) != 0)" doesn't work either. Also "if (!key($array))" is probably different from what you expect. And of course "isset(key($array))" doens't work either. Best regards, Marcus

Pierre Joye

20 years ago
On Sat, 27 May 2006 23:52:41 +0200 helly@php.net (Marcus Boerger) wrote:
> Hello Matthew, > > Saturday, May 27, 2006, 11:36:16 PM, you wrote: > > > Pierre wrote: > >> On 5/27/06, Marcus Boerger <helly@php.net> wrote: > >>> - bool array(array $array) > >>> > >>> cehcks whether arra position is valid (e.g. like > >>> "key($array) !== NULL") > >> > >> I don't understand this one. > >> > > > I think you have to listen to psychedelic music and take a hit of > > LSD first. > > Actually the point is that you cannot simply do stuff like > "while(key($array))". And "while(key($array) != 0)" doesn't work > either. Also "if (!key($array))" is probably different from what you > expect. And of course "isset(key($array))" doens't work either.
Ok, I got it now. The name is a bit confusing, array_valid has a different meaning that what it would do. array_key_valid is already better. However I still prefer to write: (key($arr) !== NULL) +0 here :) -- Pierre

Andi Gutmans

20 years ago
Zeev and I designed each() to deprecate key()/current()/etc. which came from PHP/FI 2. Maybe not exactly what you're looking for but just want to point out that there have always been some issues with the latter functions. If each() isn't suitable (and/or you want something quicker) than I'm OK with an array_* function but I don't like array_valid(). It sounds too much like is_array() and implies the array is valid. Maybe something like array_valid_position()? At 02:52 PM 5/27/2006, Marcus Boerger wrote:

Marcus Börger

20 years ago
Hello Andi, Wednesday, May 31, 2006, 5:28:47 AM, you wrote:
> Zeev and I designed each() to deprecate key()/current()/etc. which > came from PHP/FI 2. Maybe not exactly what you're looking for but > just want to point out that there have always been some issues with > the latter functions. > If each() isn't suitable (and/or you want something quicker) than I'm > OK with an array_* function but I don't like array_valid(). It sounds > too much like is_array() and implies the array is valid. Maybe > something like array_valid_position()?
Also good, i just chose the name becuase it's close to Iterator::valid(). I am however more interested in the array_has_more() thingie. Often enough one runs into a problem where the last entry of a list has a slightly different behavior.
> At 02:52 PM 5/27/2006, Marcus Boerger wrote: >>Hello Matthew, >> >>Saturday, May 27, 2006, 11:36:16 PM, you wrote: >> >> > Pierre wrote: >> >> On 5/27/06, Marcus Boerger <helly@php.net> wrote: >> >>> - bool array(array $array) >> >>> >> >>> cehcks whether arra position is valid (e.g. like "key($array) !== >> >>> NULL") >> >> >> >> I don't understand this one. >> >> >> >> > I think you have to listen to psychedelic music and take a hit of >> LSD first. >> >>Actually the point is that you cannot simply do stuff like >>"while(key($array))". And "while(key($array) != 0)" doesn't work either. >>Also "if (!key($array))" is probably different from what you expect. >>And of course "isset(key($array))" doens't work either. >> >>Best regards, >> Marcus >> >>-- >>PHP Internals - PHP Runtime Development Mailing List >>To unsubscribe, visit: http://www.php.net/unsub.php
Best regards, Marcus

Eric Fredj

20 years ago
Hi, Took from Java world, it could be something like array_has_next() which is more significant because return boolean is only about the next value not about all the next values. On 6/3/06, Marcus Boerger <helly@php.net> wrote:

Marcus Börger

20 years ago
Hello Eric, our iterators have next() and valid() in separate functions. That alone makes them way more powerful then java' iterators. In SPL we have an iterator wrapper called CachingIterator that has a method has_more() which has a boolean return value that allows to check whether a call to next() leaves the iterator valid or not. So changing the name would only add confusion. best regards marcus Sunday, June 4, 2006, 1:17:55 PM, you wrote:
> Hi,
> Took from Java world, it could be something like array_has_next() which is > more significant because return boolean is only about the next value not > about all the next values.
> On 6/3/06, Marcus Boerger <helly@php.net> wrote: >> >> Hello Andi, >> >> Wednesday, May 31, 2006, 5:28:47 AM, you wrote: >> >> > Zeev and I designed each() to deprecate key()/current()/etc. which >> > came from PHP/FI 2. Maybe not exactly what you're looking for but >> > just want to point out that there have always been some issues with >> > the latter functions. >> > If each() isn't suitable (and/or you want something quicker) than I'm >> > OK with an array_* function but I don't like array_valid(). It sounds >> > too much like is_array() and implies the array is valid. Maybe >> > something like array_valid_position()? >> >> Also good, i just chose the name becuase it's close to Iterator::valid(). >> I am however more interested in the array_has_more() thingie. Often enough >> one runs into a problem where the last entry of a list has a slightly >> different behavior. >> >> > At 02:52 PM 5/27/2006, Marcus Boerger wrote: >> >>Hello Matthew, >> >> >> >>Saturday, May 27, 2006, 11:36:16 PM, you wrote: >> >> >> >> > Pierre wrote: >> >> >> On 5/27/06, Marcus Boerger <helly@php.net> wrote: >> >> >>> - bool array(array $array) >> >> >>> >> >> >>> cehcks whether arra position is valid (e.g. like "key($array) !== >> >> >>> NULL") >> >> >> >> >> >> I don't understand this one. >> >> >> >> >> >> >> > I think you have to listen to psychedelic music and take a hit of >> >> LSD first. >> >> >> >>Actually the point is that you cannot simply do stuff like >> >>"while(key($array))". And "while(key($array) != 0)" doesn't work either. >> >>Also "if (!key($array))" is probably different from what you expect. >> >>And of course "isset(key($array))" doens't work either. >> >> >> >>Best regards, >> >> Marcus >> >> >> >>-- >> >>PHP Internals - PHP Runtime Development Mailing List >> >>To unsubscribe, visit: http://www.php.net/unsub.php >> >> >> >> >> Best regards, >> Marcus >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >>
Best regards, Marcus

Marcus Börger

20 years ago
Hello Eric again, forget the last mail, you're right it is hasNext() in php, too. So it should be array_has_next() as well. Thanks to michael for reminding me. I got confused with the original implementation (i shouldn't have changed the name). best regards marcus Sunday, June 4, 2006, 1:39:04 PM, you wrote:
> Hello Eric,
> our iterators have next() and valid() in separate functions. That alone > makes them way more powerful then java' iterators. In SPL we have an > iterator wrapper called CachingIterator that has a method has_more() > which has a boolean return value that allows to check whether a call to > next() leaves the iterator valid or not. So changing the name would only > add confusion.
> best regards > marcus
> Sunday, June 4, 2006, 1:17:55 PM, you wrote:
>> Hi,
>> Took from Java world, it could be something like array_has_next() which is >> more significant because return boolean is only about the next value not >> about all the next values.
>> On 6/3/06, Marcus Boerger <helly@php.net> wrote: >>> >>> Hello Andi, >>> >>> Wednesday, May 31, 2006, 5:28:47 AM, you wrote: >>> >>> > Zeev and I designed each() to deprecate key()/current()/etc. which >>> > came from PHP/FI 2. Maybe not exactly what you're looking for but >>> > just want to point out that there have always been some issues with >>> > the latter functions. >>> > If each() isn't suitable (and/or you want something quicker) than I'm >>> > OK with an array_* function but I don't like array_valid(). It sounds >>> > too much like is_array() and implies the array is valid. Maybe >>> > something like array_valid_position()? >>> >>> Also good, i just chose the name becuase it's close to Iterator::valid(). >>> I am however more interested in the array_has_more() thingie. Often enough >>> one runs into a problem where the last entry of a list has a slightly >>> different behavior. >>> >>> > At 02:52 PM 5/27/2006, Marcus Boerger wrote: >>> >>Hello Matthew, >>> >> >>> >>Saturday, May 27, 2006, 11:36:16 PM, you wrote: >>> >> >>> >> > Pierre wrote: >>> >> >> On 5/27/06, Marcus Boerger <helly@php.net> wrote: >>> >> >>> - bool array(array $array) >>> >> >>> >>> >> >>> cehcks whether arra position is valid (e.g. like "key($array) !== >>> >> >>> NULL") >>> >> >> >>> >> >> I don't understand this one. >>> >> >> >>> >> >>> >> > I think you have to listen to psychedelic music and take a hit of >>> >> LSD first. >>> >> >>> >>Actually the point is that you cannot simply do stuff like >>> >>"while(key($array))". And "while(key($array) != 0)" doesn't work either. >>> >>Also "if (!key($array))" is probably different from what you expect. >>> >>And of course "isset(key($array))" doens't work either. >>> >> >>> >>Best regards, >>> >> Marcus >>> >> >>> >>-- >>> >>PHP Internals - PHP Runtime Development Mailing List >>> >>To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >>> >>> >>> Best regards, >>> Marcus >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>>
> Best regards, > Marcus
Best regards, Marcus

bertrand Gugger

20 years ago
Matthew C. Kavanagh wrote:
> Pierre wrote: > >> On 5/27/06, Marcus Boerger <helly@php.net> wrote: >> >>> - bool array(array $array) >>> >>> cehcks whether arra position is valid (e.g. like "key($array) !== >>> NULL") >> >> >> I don't understand this one. >> > > I think you have to listen to psychedelic music and take a hit of LSD > first.
Who should ? Marcus, Pierre, you or me ? I don't get the question either. if it's english, what position , in which situation ?
-- toggg Sorry, in the mean time I see it's solved , that was only typos, but your comment was not right orienting the discussion. Be constructive.

Michael Wallner

20 years ago
Pierre wrote:
> On 5/27/06, Marcus Boerger <helly@php.net> wrote:
>> - bool array(array $array) >> >> cehcks whether arra position is valid (e.g. like "key($array) !== >> NULL") > > > I don't understand this one.
I think he meant valid() or array_valid().
-- Michael

Jared Williams

20 years ago
> -----Original Message----- > From: Marcus Boerger [mailto:helly@php.net] > Sent: 27 May 2006 22:28 > To: internals@lists.php.net > Subject: [PHP-DEV] RFC array functions > > Hello internals, > > i'd like to add two array functions: > > - bool array_has_more(array $array) > > checks whether $array has more elements after current position or > if array is at last position, preferable working inside foreach
Useful.
> - bool array(array $array) > > cehcks whether arra position is valid (e.g. like > "key($array) !== NULL")
How do you disambiguate between this and $array = array('foo', 'bar'); $anotherArray = array($array); making array(0 => array(0 => 'foo', 1 => 'bar')) Jared

Marcus Börger

20 years ago
Hello Jared, UPS i see my failure in writing. I meant array_valid($array) of course :-) i have always been better in writing patches then telling tales. best regards marcus
>> - bool array(array $array) >> >> cehcks whether arra position is valid (e.g. like >> "key($array) !== NULL")
> How do you disambiguate between this and
> $array = array('foo', 'bar'); > $anotherArray = array($array);
> making array(0 => array(0 => 'foo', 1 => 'bar'))
Best regards, Marcus

Kevin Waterson

20 years ago
This one time, at band camp, Marcus Boerger <helly@php.net> wrote:
> Hello Jared, > > > UPS i see my failure in writing. I meant array_valid($array) of course :-) > > i have always been better in writing patches then telling tales.
I like the idea of an SPL feel to array functions Kevin
-- "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote."

Greg Beaver

20 years ago
Marcus Boerger wrote:
> Hello internals, > > i'd like to add two array functions: > > - bool array_has_more(array $array)
I don't like "array_has_more" array_at_end() would work better for me since the function that makes it evaluate as true is: end($array); Greg

boots

20 years ago
--- Greg Beaver <cellog@php.net> wrote:
> Marcus Boerger wrote: > > Hello internals, > > > > i'd like to add two array functions: > > > > - bool array_has_more(array $array) > > I don't like "array_has_more" > > array_at_end() > > would work better for me since the function that makes it evaluate as > true is: > > end($array);
Hi and please pardon my intrusion to your discussion. Aren't the semantics of functions of this sort usually named is_* in PHP? I would suggest something such as is_last(). I suppose too that objects that implement the appropriate iteration interfaces could use this? If so, would using "array" for naming purposes make things less clear? To me, none of the existing array_* functions have an "if" semanatic and I think that is a good thing. Thanks. boots __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Marcus Börger

20 years ago
Hello boots, there are two rules that could be applied. First is the extension name followed by underscore followed by functional name. Second is "is_" followed by type condition. The important thing here is that the latter rule so far has been mainly used for type checks. And in this case we are not checking for a type. best regards marcus Sunday, May 28, 2006, 9:00:56 AM, you wrote:
> --- Greg Beaver <cellog@php.net> wrote: >> Marcus Boerger wrote: >> > Hello internals, >> > >> > i'd like to add two array functions: >> > >> > - bool array_has_more(array $array) >> >> I don't like "array_has_more" >> >> array_at_end() >> >> would work better for me since the function that makes it evaluate as >> true is: >> >> end($array);
> Hi and please pardon my intrusion to your discussion. Aren't the semantics of > functions of this sort usually named is_* in PHP? I would suggest something > such as is_last(). I suppose too that objects that implement the appropriate > iteration interfaces could use this? If so, would using "array" for naming > purposes make things less clear? To me, none of the existing array_* functions > have an "if" semanatic and I think that is a good thing.
> Thanks. > boots
> __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com
Best regards, Marcus

Marcus Börger

20 years ago
Hello Greg, works too of course. I whose array_has_more() becasue there is a compareable iterator function namely CachingIterator::hasMore(). best regards marcus Sunday, May 28, 2006, 7:00:54 AM, you wrote:
> Marcus Boerger wrote: >> Hello internals, >> >> i'd like to add two array functions: >> >> - bool array_has_more(array $array)
> I don't like "array_has_more"
> array_at_end()
> would work better for me since the function that makes it evaluate as > true is:
> end($array);
> Greg
Best regards, Marcus

Greg Beaver

20 years ago
Marcus Boerger wrote:
> Hello internals, > > i'd like to add two array functions: > > - bool array_has_more(array $array)
I don't like "array_has_more" array_at_end() would work better for me since the function that makes it evaluate as true is: end($array); Greg P.S. sorry if this double posts, weird mail client issues

Marcus Börger

20 years ago
Hello internals, just as a reminder for those that insist on being heared - you have been heared. Here is your second try. I am not going to wait till the dawn of time. best regards marcus Saturday, May 27, 2006, 11:27:43 PM, you wrote:
> Hello internals,
> i'd like to add two array functions:
> - bool array_has_more(array $array)
> checks whether $array has more elements after current position or > if array is at last position, preferable working inside foreach
> - bool array(array $array)
> cehcks whether arra position is valid (e.g. like "key($array) !== NULL")
> Any comments?
> Best regards, > Marcus
Best regards, Marcus

Pierre Joye

20 years ago
On 5/30/06, Marcus Boerger <helly@php.net> wrote:
> Hello internals, > > just as a reminder for those that insist on being heared - you have been > heared. Here is your second try. I am not going to wait till the dawn of > time.
It is a long process but we will get somewhere. One or two work days is not he dawn of time to wait. Patience is a vertue :) --Pierre

Marcus Börger

20 years ago
Hello Pierre, Tuesday, May 30, 2006, 9:39:44 PM, you wrote:
> On 5/30/06, Marcus Boerger <helly@php.net> wrote: >> Hello internals, >> >> just as a reminder for those that insist on being heared - you have been >> heared. Here is your second try. I am not going to wait till the dawn of >> time.
> It is a long process but we will get somewhere.
> One or two work days is not he dawn of time to wait. Patience is a vertue :)
Lemme cite Rollo: "Ignorance is bliss"...that seems to be the motto here :-) Best regards, Marcus

Alexander Pak

20 years ago
As for me I don't really like "array_has_more" name.. maybe array_end? On 5/31/06, Marcus Boerger <helly@php.net> wrote:
> > Hello internals, > > just as a reminder for those that insist on being heared - you have been > heared. Here is your second try. I am not going to wait till the dawn of > time. > > best regards > marcus > > Saturday, May 27, 2006, 11:27:43 PM, you wrote: > > > Hello internals, > > > i'd like to add two array functions: > > > - bool array_has_more(array $array) > > > checks whether $array has more elements after current position or > > if array is at last position, preferable working inside foreach > > > - bool array(array $array) > > > cehcks whether arra position is valid (e.g. like "key($array) !== > NULL") > > > Any comments? > > > Best regards, > > Marcus > > > > > Best regards, > Marcus > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- regards, Alexander Pak

Pierre Joye

20 years ago
On Wed, 31 May 2006 00:58:34 +0500 irokez@gmail.com ("Alexander Pak") wrote: On 5/30/06, Alexander Pak <irokez@gmail.com> wrote:
> As for me I don't really like "array_has_more" name.. maybe array_end?
I find *end confusing as well. array_has_more is unambiguous and perfectly matches the function purpose. -- Pierre

Andi Gutmans

20 years ago
At 01:00 PM 5/30/2006, Pierre wrote:
>On Wed, 31 May 2006 00:58:34 +0500 >irokez@gmail.com ("Alexander Pak") wrote: > >On 5/30/06, Alexander Pak <irokez@gmail.com> wrote: > > As for me I don't really like "array_has_more" name.. maybe array_end? > >I find *end confusing as well. array_has_more is unambiguous and >perfectly matches the function purpose.
Fine too. Andi