define('test',2);
if(isset(test))echo 'hi';
views:
89answers:
3
A:
It isn't valid PHP syntax.
define('test',2);
if(isset(test)){
echo 'hi';
}
This is the correct version of what you posted.
Tyler Smith
2010-01-06 03:00:32
you dont need to add braces if it is only a 1 liner code
Treby
2010-01-06 03:02:09
PHP Parse error: parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM'
2010-01-06 03:03:32
How is the non bracket version incorrect? As far as I know it's perfectly correct, just like you can choose to use brackets or not.
johnnyArt
2010-01-06 03:04:55
I added the braces in for readability by myself. The change I was making was the missing paren.
Tyler Smith
2010-01-06 03:06:35
+4
A:
isset is meant for variables. You should use defined instead:
define('test',2);
if(defined('test')) echo 'hi';
You're also missing a bracket after the isset.
Brian McKenna
2010-01-06 03:04:00
+1 - this is the only correct answer so far. (switch `define` to `defined`, thougH)
pix0r
2010-01-06 03:06:15
+1
A:
As others stated, you're missing a closing ) on your "if" statement. Formatting statements with brackets often helps trace errors, since it splits the code onto more lines. There's generally no reason to be brief with PHP.
Also, you probably want to use defined('test') here. http://php.net/manual/en/function.defined.php
gabrielk
2010-01-06 03:05:43