Page 1 of 1
constant by define
Posted: Mon Apr 13, 2009 10:12 am
by szita1
hi all,
im new to php and im stuck with a "constant" problem.
i was studying a code snippet and trying to creat a constant with define() like this:
define("ABC",1,TRUE).
i dont understand why it results nothing if the second parameter is 0.
The consant type is boolean and it works fine if the parameter is
1, but if it is 0, it seems as if it doesnt handle it at all.
thanks
Re: constant by define
Posted: Mon Apr 13, 2009 10:41 am
by requinix
What do you mean "handle"? What code are you using to check whether ABC "works fine"?
Re: constant by define
Posted: Mon Apr 13, 2009 10:59 am
by n00b Saibot
Constant is just that... a constant value... not a boolean check....
can we see your code please?
Re: constant by define
Posted: Mon Apr 13, 2009 11:55 am
by szita1
this is what i want to figure out:
define("EW_IS_WINDOWS", (strtolower(substr(PHP_OS, 0, 3)) === 'win'), TRUE);
if im not mistaken, "EW_IS_WINDOWS" returns true if the operating system is Win OS, but what if it is not.
when i changed 'win' to 'wi', print EW_IS_WINDOWS returned nothing. it should return false, shouldnt it.
Re: constant by define
Posted: Mon Apr 13, 2009 12:07 pm
by php_east
szita1 wrote:this is what i want to figure out:
define("EW_IS_WINDOWS", (strtolower(substr(PHP_OS, 0, 3)) === 'win'), TRUE);
if im not mistaken, "EW_IS_WINDOWS" returns true if the operating system is Win OS, but what if it is not.
when i changed 'win' to 'wi', print EW_IS_WINDOWS returned nothing. it should return false, shouldnt it.
the way PHP handles it is that if you print a boolean false value, it prints nothing. that does not meant the value is not there or is 'not handled'. if the values is true it prints a '1'. if you want to see the actual type and value do a var_dump. you will see then either boolean values.
Code: Select all
define("EW_IS_WINDOWS", (strtolower(substr(PHP_OS, 0, 3)) === 'win'), TRUE);
var_dump(EW_IS_WINDOWS);