constant by define

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
szita1
Forum Newbie
Posts: 10
Joined: Mon Apr 13, 2009 10:03 am

constant by define

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: constant by define

Post by requinix »

What do you mean "handle"? What code are you using to check whether ABC "works fine"?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Re: constant by define

Post by n00b Saibot »

Constant is just that... a constant value... not a boolean check....

can we see your code please?
szita1
Forum Newbie
Posts: 10
Joined: Mon Apr 13, 2009 10:03 am

Re: constant by define

Post 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.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: constant by define

Post 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); 
Post Reply