Um, Yasuo, have you looked at array_walk implementation and ascertained it is safe to change array structure while using it?
Because I'm worried you're changing docs without doing so.
--
Sent from Samsung Mobile
Andrew Faulds
http://ajf.me/
Yasuo Ohgaki yohgaki@ohgaki.net wrote:
Hi,
2012/8/22 Levi Morrison morrison.levi@gmail.com:
Hi,
2012/8/16 Rasmus Schultz rasmus@mindplay.dk:
How come there is no straight-foward obvious way to simply remove a given
value from an array?Just look at the number of horrible ways people solve this obvious problem:
http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key
Shouldn't we have something simple, like:
array_remove($array, $value) : array (returns a new array)
and/or
array_delete(&$array, $value) : bool (modifies array directly)
?
It was amazing that this thread has close to 90 mails.
I've added some use cases of array_udelete() to wiki, since
some people fails to see how it could be useful. I also bring
back toarray_walk()
version of equivalent example. I just
don't see any reason why we should replace it with slower
foreach() version.I think the RFC page is almost complete.
https://wiki.php.net/rfc/array_delete
Any more comments?
--
Yasuo Ohgaki
yohgaki@ohgaki.netTake a look at:
http://php.net/manual/en/function.array-walk.php#refsect1-function.array-walk-parametersLook at funcname parameter. Notice:
Only the values of the array may potentially be changed; its structure cannot be altered, i.e., the programmer cannot add, unset or reorder elements. If the callback does not respect this requirement, the behavior of this function is undefined, and unpredictable.
I'm just going to change the behavior back when you switch it to
array_walk. It's less clear and technically undefined.
Ok, then my commit to the doc was outstanding still.
Old PHP was behaved badly with reference variables.
I'll remove obsolete statement.
I'll fix it later.
Thank you.
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi,
2012/8/22 Andrew Faulds ajf@ajf.me:
Um, Yasuo, have you looked at array_walk implementation and ascertained it
is safe to change array structure while using it?Because I'm worried you're changing docs without doing so.
Simply deleting current element is safe.
It's done in everywhere in PHP. It's just like deleting elements with
zend hash.
array_walk()
could bite users.
If programmer sort or delete element to be processed next, it causes problem.
PHP programmer will not sort or delete next element to processed while working
with zend hash, but average PHP users do not care about internal.
I finally understand why people use array_filter()
to delete elements and
I think we should have array_udelete() since the API is much safer than
array_walk()
.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
--
Sent from Samsung Mobile
Andrew Faulds
http://ajf.me/Yasuo Ohgaki yohgaki@ohgaki.net wrote:
Hi,
2012/8/22 Levi Morrison morrison.levi@gmail.com:
Hi,
2012/8/16 Rasmus Schultz rasmus@mindplay.dk:
How come there is no straight-foward obvious way to simply remove a
given
value from an array?Just look at the number of horrible ways people solve this obvious
problem:http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key
Shouldn't we have something simple, like:
array_remove($array, $value) : array (returns a new array)
and/or
array_delete(&$array, $value) : bool (modifies array directly)
?
It was amazing that this thread has close to 90 mails.
I've added some use cases of array_udelete() to wiki, since
some people fails to see how it could be useful. I also bring
back toarray_walk()
version of equivalent example. I just
don't see any reason why we should replace it with slower
foreach() version.I think the RFC page is almost complete.
https://wiki.php.net/rfc/array_delete
Any more comments?
--
Yasuo Ohgaki
yohgaki@ohgaki.netTake a look at:
http://php.net/manual/en/function.array-walk.php#refsect1-function.array-walk-parameters
Look at funcname parameter. Notice:
Only the values of the array may potentially be changed; its structure
cannot be altered, i.e., the programmer cannot add, unset or reorder
elements. If the callback does not respect this requirement, the behavior of
this function is undefined, and unpredictable.I'm just going to change the behavior back when you switch it to
array_walk. It's less clear and technically undefined.Ok, then my commit to the doc was outstanding still.
Old PHP was behaved badly with reference variables.
I'll remove obsolete statement.I'll fix it later.
Thank you.--
Yasuo Ohgaki
yohgaki@ohgaki.net