PHP: references in assignment -
i'm not guru in php, used language plenty know lot of quirks , oddities of syntax , built-in functions. new me:
$ok = is_acceptable($_session['config']); $config = $ok ? &$_session['config'] : retrieve_config(); the compiler tells me & unexpected. wrapping &$_session['config'] in parenthesis won't alter anything, had resolve this:
if ($ok) $config = &$_session['config']; else $config = retrieve_config(); the alternative drop & altogether, create re-create of value , tend avoid that.
why syntax wrong? out of curiosity. bet & mistaken and bitwise operator.
$config = $ok ? &$_session['config'] : retrieve_config();
= in case assigns result of ternary operator, using reference not have effect if syntax accepted.
instead, should think of =& operator, right side must variable, never expression. these cases invalid:
$a =& "abc"; // scalar $a =& ($b); // look php
No comments:
Post a Comment