Open
Description
Description
I wanted to do
foreach((is_array($value) ? $value['images'] : $value->images) as &$image) {
// process $image
}
but that silently fail (!) because foreach will create an internal copy and iterate the copy (see `&$image);
So instead I tried:
$iter = is_array($value) ? (&$value['images']) : (&$value->images);
foreach($iter as &$image) {
// process $image
}
but that fail because ternary reference assignment is illegal (?)
So instead I have to do
if(is_array($value)){
$iter = &$value['images'];
} else {
$iter = &$value->images;
}
foreach($iter as &$image) {
// process $image
}
which works.
Now it feels like I'm fighting the language itself.