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
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
Pierre 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.
Hello Matthew,
Saturday, May 27, 2006, 11:36:16 PM, you wrote:
Pierre 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
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:
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
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:
Pierre 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
Hello Andi,
Wednesday, May 31, 2006, 5:28:47 AM, you wrote:
Zeev and I designed
each()
to deprecatekey()
/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.
Ifeach()
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 likeis_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:
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--
Best regards,
Marcus
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:
Zeev and I designed
each()
to deprecatekey()
/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.
Ifeach()
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 likeis_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:
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--
Best regards,
Marcus
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.
Hello Andi,
Wednesday, May 31, 2006, 5:28:47 AM, you wrote:
Zeev and I designed
each()
to deprecatekey()
/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.
Ifeach()
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 likeis_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:
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--
Best regards,
Marcus--
Best regards,
Marcus
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.
Hello Andi,
Wednesday, May 31, 2006, 5:28:47 AM, you wrote:
Zeev and I designed
each()
to deprecatekey()
/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.
Ifeach()
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 likeis_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:
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--
Best regards,
Marcus--
Best regards,
Marcus
Best regards,
Marcus
Matthew C. Kavanagh wrote:
Pierre 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.
Pierre 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
-----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 functionsHello 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
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
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."
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
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
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
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
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
Hello Pierre,
Tuesday, May 30, 2006, 9:39:44 PM, you 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
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
marcusSaturday, 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,
MarcusBest regards,
Marcus--
--
regards,
Alexander Pak
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
At 01:00 PM 5/30/2006, Pierre wrote:
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.
Fine too.
Andi