I'm upgrading an old code from PHP 4 to PHP 5 and what I often see is:
if (!$variable) {
// for example...
$variable = "test";
}
To understand the code I need to know if it was possible earlier in PHP 4 times to check the existence of a variable by doing so.
I'm sorry but I couldn't google the answer to that.
if (!$variable)tests if$variableevaluates tofalse. According to the chapter Converting to boolean, a lot of things evaluate tofalse:Therefore, using this kind of code to test if a variable is already set is dangerous. Also, it will generate notices when the variable is used but not set.
Yes, the code will execute with PHP 4. But you may get unexpected results when
$variableis set to0, the empty string or the string'0'.For cleaner code, you should use isset:
According to the documentation,
issetwas introduced with PHP 4.