Srsly PHP, why can’t I do this:
$value = isset($myGPCWrapper->Get("value")) ? $myGPCWrapper->Get("value") : $default;
Resulting in this:
Fatal error: Can’t use method return value in write context in /path/to/my/script.php on line 21
And instead I have to do this:
$foo = $myGPCWrapper->Get("value"); $value = isset($foo) ? $foo : $default;
or
$value = isset($_GET['value']) ? $myGPCWrapper->Get("value") : $default;
I mean… how is isset writing to my variable?!
April 8th, 2010 at 10:09 am
isset() isn’t a function. It’s a language construct that checks whether or not the given variable exists. You’re not passing isset() the name of a variable, you’re trying to pass it a value, returned by a function call.
Shouldn’t it be the responsibility of $myGPCWrapper to ensure the integrity of the values it stores?
April 8th, 2010 at 10:12 am
I didn’t explain very well… :/ Try this:
isset(7)
isset(chr(64))
Both are passing values to isset(), rather than varaibles.
April 8th, 2010 at 11:26 am
Thanks for the explanation:
That I think is the key. Sure $myGPCWrapper could integrity check – but I wanted to check if the value is passed in the query string at all – if not, then fall back to a value retrieved from session. It turns out $myGPCWrapper (incidentally, not written by me!) returns boolean false if value is not set, and a string otherwise so I ended up with: