Page 1 of 1

defined is behaving strangely

Posted: Fri Jul 29, 2005 11:05 am
by BDKR
Check this out. The below doesn't seem to be working.

Code: Select all

if(defined(PVL_FETCH_MODE))
    { $mode=PVL_FETCH_MODE; }
Strange as that's perfectly viable and correct. Or at least I think it is. Can someone tell me I'm high and the above code is wrong in someway? Otherwise, I had to do the below workaround to get what I needed.

Code: Select all

if(in_array('PVL_FETCH_MODE', get_defined_constants()))
    { $mode=PVL_FETCH_MODE; }
Sheesh..... Maybe I need to stop developing on Windows.

Posted: Fri Jul 29, 2005 11:14 am
by nielsene
Yup that's incorrect. You have the give defined() the name of the constant as a string. So you have to quote it.

Code: Select all

if (defined('PVL_FETCH_MODE'))
(Since otherwise PHP replaces the constant with its defined value, before calling defined.)

Posted: Fri Jul 29, 2005 1:47 pm
by BDKR
Thanx ripper. I was wondering what the hell was going on. Now I can get rid of that crafty abomination of a workaround. :evil: