tags:

views:

89

answers:

3
define('test',2);
if(isset(test))echo 'hi';
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
you dont need to add braces if it is only a 1 liner code
Treby
PHP Parse error: parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM'
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
I added the braces in for readability by myself. The change I was making was the missing paren.
Tyler Smith
+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
+1 - this is the only correct answer so far. (switch `define` to `defined`, thougH)
pix0r
Sorry, typo - now fixed.
Brian McKenna
So you think `test` here is not variable,then what is it?
It's a named constant. See: http://php.net/define
pix0r
+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