php - ternary operator with ampersand -
this question has answer here:
i use followed somewhere in code:
if (isset($flat[$pid])) { $branch = &$flat[$pid]['items']; } else { $branch = &$tree; } all ok, when want short to:
$branch = isset($flat[$pid]) ? &$flat[$pid]['items'] : &$tree; i get:
syntax error, unexpected '&' ...
what i'm doing wrong?
this because ternary operator expression, doesn't evaluate variable. , quote manual:
note: please note ternary operator expression, , doesn't evaluate variable, result of expression. important know if want return variable reference. statement return $var == 42 ? $a : $b; in return-by-reference function therefore not work , warning issued in later php versions.
Comments
Post a Comment