Firstly, you made an error and did
if (!test) {
Rather than
if (! $test) {
Which is, I suspect, what you meant.
Secondly, you have to understand what PHP's definition of being true is.
If you attempt to apply a boolean operator to something or use it in a boolean context, PHP will implicitly cast it into a boolean.
This means, basically speaking,
- Any number other than 0 is considered true
- Any string which is not the empty string is considered true
- Any object or resource (I think) is considered true
- Null or an undefined value are considered false
The PHP docs can help you here. This may not be what you expect, specifically, the string "false" will of course be considered true.
You should enable warnings ALL THE TIME, ideally triggering fatal errors. Bareword warnings are usually the result of a programming error.
There should be an option in PHP to disable bareword string constants and cause a parse error instead IMHO.
Mark