Re:What PHP 5.5 might look like
by snorkel on Thursday July 12, 2012 @11:22AM
(#4234939)
Conspicuously absent from PHP:
... in order to copy-by-value on arrays containing references. Currently to do that you have to do a very fragile hack like this:
... which is vulnerable to key-value collisions ... or you have to write your own homebrew array copy-by-value function.
[ Parent
| on HN ]
Still ugly, but at least it won't crap out if your data has duplicate values:
$copy = array_map( function($v) { return $v; }, $original );Very simple.
Either:
$copy = $original;
Or, if you must have a function, function array_copy(array $a) {
return $a;
}
Arrays use the normal copy-on-write semantics of PHP. They are not passed by reference or object handle...The only potential issue is if the array contains references deeper in.
Re:What PHP 5.5 might look like
by TazeTSchnitzel on Thursday July 12, 2012 @11:38AM
(#4235074)
File a bug report :)
Better yet, file an RFC and a pull request.
Re:What PHP 5.5 might look like
by TazeTSchnitzel on Friday July 13, 2012 @04:32AM
(#4238847)
Yep. That's what I'm trying to do for something else :D