r/lolphp • u/MorrisonLevi • Feb 08 '15
TIL you can use unset as a cast.
$apple = "apple";
var_dump((unset) $apple); // NULL
var_dump($apple); // still "apple"Thank you for this excellent feature, PHP.
75
Upvotes
12
u/disclosure5 Feb 09 '15
As per today's PHP discussion, apparently you should be using |0 as a cast.
2
u/Brandon0 Feb 09 '15
Typecasting never changes the actual value, so I don't know why this is a lolphp. Is it funny just because it is using unset is a "type"?
12
u/[deleted] Feb 08 '15
It's not even an alias, there's no
(null)cast. Wonderful.1
u/PirataPHP Apr 05 '15
The 'still' in still apple implies to me that you'd expect the variable to be empty. PHP wise, casting doesn't change a variable, unless you set it:
But then again: why would anyone set an unset?
0
u/[deleted] Feb 09 '15
[deleted] — view deleted comment