# RFC array functions

- Thread: https://externals.io/message/23726
- Original archive: https://news-web.php.net/php.internals/23726
- Started by Marcus Boerger on 2006-05-27T21:27:43+00:00
- Messages: 24
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #23726 — Marcus Boerger — 2006-05-27T21:27:43+00:00

URL: https://externals.io/message/23726#23726

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

---

## #23727 — Pierre — 2006-05-27T21:32:03+00:00

URL: https://externals.io/message/23726#23727 · In reply to: #23726

> 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

---

## #23728 — Matthew C. Kavanagh — 2006-05-27T21:36:16+00:00

URL: https://externals.io/message/23726#23728 · In reply to: #23727

Pierre wrote:
> 
> > […]
> 
> I don't understand this one.
> 

I think you have to listen to psychedelic music and take a hit of LSD first.

---

## #23729 — Michael Wallner — 2006-05-27T21:48:51+00:00

URL: https://externals.io/message/23726#23729 · In reply to: #23727

Pierre wrote:
> 

> > […]
> 
> 
> I don't understand this one.

I think he meant valid() or array_valid().

-- 
Michael

---

## #23731 — Marcus Boerger — 2006-05-27T21:52:41+00:00

URL: https://externals.io/message/23726#23731 · In reply to: #23728

Hello Matthew,

Saturday, May 27, 2006, 11:36:16 PM, you wrote:

> Pierre wrote:
> > […]

> 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

---

## #23730 — Jared Williams — 2006-05-27T21:53:28+00:00

URL: https://externals.io/message/23726#23730 · In reply to: #23726

> -----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

---

## #23732 — Marcus Boerger — 2006-05-27T21:56:27+00:00

URL: https://externals.io/message/23726#23732 · In reply to: #23730

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


> > […]

> 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

---

## #23737 — Pierre — 2006-05-28T01:20:15+00:00

URL: https://externals.io/message/23726#23737 · In reply to: #23731

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:
> 
> > […]
> 
> > […]
> 
> 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

---

## #23740 — bertrand Gugger — 2006-05-28T03:12:21+00:00

URL: https://externals.io/message/23726#23740 · In reply to: #23728

Matthew C. Kavanagh wrote:
> Pierre wrote:
> 
> > […]
> 
> 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.

---

## #23741 — Greg Beaver — 2006-05-28T05:00:54+00:00

URL: https://externals.io/message/23726#23741 · In reply to: #23726

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

---

## #23743 — Greg Beaver — 2006-05-28T05:01:38+00:00

URL: https://externals.io/message/23726#23743 · In reply to: #23726

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

---

## #23749 — Marcus Boerger — 2006-05-28T09:24:27+00:00

URL: https://externals.io/message/23726#23749 · In reply to: #23741

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:
> > […]

> 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

---

## #23775 — Kevin Waterson — 2006-05-29T20:46:51+00:00

URL: https://externals.io/message/23726#23775 · In reply to: #23732

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."

---

## #23784 — Marcus Boerger — 2006-05-30T19:15:02+00:00

URL: https://externals.io/message/23726#23784 · In reply to: #23726

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

---

## #23788 — Pierre — 2006-05-30T19:39:44+00:00

URL: https://externals.io/message/23726#23788 · In reply to: #23784

> 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

---

## #23789 — Marcus Boerger — 2006-05-30T19:45:00+00:00

URL: https://externals.io/message/23726#23789 · In reply to: #23788

Hello Pierre,

Tuesday, May 30, 2006, 9:39:44 PM, you wrote:

> 
> > […]

> 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

---

## #23791 — Alexander Pak — 2006-05-30T19:58:34+00:00

URL: https://externals.io/message/23726#23791 · In reply to: #23784

As for me I don't really like "array_has_more" name.. maybe array_end?


>
> 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:
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
> NULL")
>
> > […]
>
> > […]
>
>
>
>
> Best regards,
> Marcus
>
> --
> 
> 
>
>


-- 
regards,
Alexander Pak

---

## #23792 — Pierre — 2006-05-30T20:00:35+00:00

URL: https://externals.io/message/23726#23792 · In reply to: #23791

On Wed, 31 May 2006 00:58:34 +0500
irokez@gmail.com ("Alexander Pak") 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

---

## #23810 — Andi Gutmans — 2006-05-31T03:28:47+00:00

URL: https://externals.io/message/23726#23810 · In reply to: #23731

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:
>Hello Matthew,
>
>Saturday, May 27, 2006, 11:36:16 PM, you wrote:
>
> > […]
>
> > […]
> 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

---

## #23811 — Andi Gutmans — 2006-05-31T03:29:57+00:00

URL: https://externals.io/message/23726#23811 · In reply to: #23792

At 01:00 PM 5/30/2006, Pierre wrote:
>On Wed, 31 May 2006 00:58:34 +0500
>irokez@gmail.com ("Alexander Pak") wrote:
>
>
> > […]
>
>I find *end confusing as well. array_has_more is unambiguous and
>perfectly matches the function purpose.

Fine too.

Andi

---

## #23874 — Marcus Boerger — 2006-06-03T10:38:01+00:00

URL: https://externals.io/message/23726#23874 · In reply to: #23810

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:
> > […]




Best regards,
 Marcus

---

## #23915 — Eric Fredj — 2006-06-04T11:17:55+00:00

URL: https://externals.io/message/23726#23915 · In reply to: #23874

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.


>
> Hello Andi,
>
> Wednesday, May 31, 2006, 5:28:47 AM, you wrote:
>
> > […]
>
> 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.
>
> > […]
>
>
>
>
> Best regards,
> Marcus

---

## #23916 — Marcus Boerger — 2006-06-04T11:39:04+00:00

URL: https://externals.io/message/23726#23916 · In reply to: #23915

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.

> 
> > […]



Best regards,
 Marcus

---

## #23917 — Marcus Boerger — 2006-06-04T11:50:36+00:00

URL: https://externals.io/message/23726#23917 · In reply to: #23916

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:

> > […]

> > […]

> > […]



> Best regards,
>  Marcus




Best regards,
 Marcus
