>why this array_push($x ? $a : $b, 'value'); produce error(Fatal error:
>Only variables can be passed by reference)
>$x = 1;
>#$x = 0;
>$a = array();
>$b = array();
>array_push($x ? $a : $b, 'value');
>i must rewrote this in
>if ($x)
>   array_push($a, 'value');
>   array_push($b, 'value');

My Theory:

In order for array_push to be reasonably efficient, the array is passed by

If it were passed by value, PHP would have to make a COPY of the array, and
the array could be VERY large...

$x ? $a : $b has to turn into a "temporary" variable, since you don't really
provide a storage place for it.

That temporary variable can't be turned into a reference.

At any rate, smushing the ? and the array_push all into one line is just
being obtuse.

Spell out what you're doing with an extra line of code and another variable:

$victim = $x ? $a : $b;
array_push($victim, 'value');

Like Music?  http://l-i-e.com/artists.htm

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to