Using parenthesis in a programming language or a scripting language usually means that it is a function.
However $_COOKIE
in php is not a function, it is an Array, to access data in arrays you use Square Braces which symbolise which index to get the data from so by doing $_COOKIE['test']
you are basicly saying: Give me the data from the index 'test'.
Now in your case you have two possibilities either you want to see if it is false by looking inside the cookie or see if it is not even there.
For this you use the isset function which bascily check if the variable is set or not.
Example
if ( isset($_COOKIE['test'] ) )
And if you want to check if the value is false and it is set you can do the following
if ( isset($_COOKIE['test']) && $_COOKIE['test'] == "false" )
One thing that you can keep in mind is that if the first test fails, it wont even bother checking the next statement if it is AND ( &&
).
And to explain why you actually get the error "Function must be a string", look at this page. It's about basic creation of functions in PHP, what you must remeber is that a function in PHP can only contain a certain type of characters where $
is not one of these. Since in PHP $
represents a Variable.
A function could look like this: _myFunction _myFunction123 myFunction
and in many other patterns aswell, but mixing it with characters like $ and % will not work.