Steven Steven - 4 months ago 12
PHP Question

PHP define is not registering constants

I'm in the prcoess of setting up my (Wordpress) solution on a new production server. I now discovere that the PHP function

is not working.

I have this line of code in my
functions.php
:

define('INCLUDE_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/storelocator/include/');


Testing the following code:

if (!defined('INCLUDE_DIR'))
echo ' NOT SET! ';


outputs
NOT SET
.

According to this page, I'm using constant correct in the
include
statement.
The rest of the code in
functions.php
is running fine. I've checked.

Is this due to some PHP configuration? I'm using PHP v5.3.8

UPDATE:

define()
is at the very top of
functions.php
file.

The
if
statement is at the very top of
some-file.php
.

I'm pretty sure
functions.php
is run before
some-file.php
.

UPDATE

It seems that I got this error because I had empty lines at the bottom of my PHP files. I removed the empty lines and now it seems to work :-/

Answer

You must call the define() function before you check to see if the constant has been defined(). If you are doing so (try putting your define call immediately above your defined call) then I can see no reason why this wouldn't work.