defined is behaving strangely

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
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

defined is behaving strangely

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.)
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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:
Post Reply