4

I'm in the prcoess of setting up my (Wordpress) solution on a new production server. I now discovere that the PHP function define 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 :-/

7
  • 3
    Are you sure that the functions.php has been included/required BEFORE you do your defined() check? To assume you've found a PHP bug on such a simple widely-used function is pushing things a bit. Commented Oct 27, 2011 at 15:15
  • can you show where the include of functions.php is in relation to the check if defined? Commented Oct 27, 2011 at 15:18
  • @Marc B - functions.php is run before any other WP template file, right? So functions.php should run before 'some.template.php` file where I used defined(). Commented Oct 27, 2011 at 16:58
  • I avoid WP's internals like the plague, so no idea. Easy enough to verify though - just have functions.php log something or output something and see if you get that before an equivalent log/output call in your main function occurs. Commented Oct 27, 2011 at 16:59
  • @Patrick - functions.php is automatically run by Wordpress before any other template files are loaded. Commented Oct 27, 2011 at 17:00

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Can you confirm you've not put the define call inside a function accidentally?
All constants for my site is put in functions.php and no where else. I'm sure of that. It works fine on my local server and my previous test server, just not on this new server.
In which case: are you absolutely positive you've edited the correct copy of the correct file? Try putting a die() statement just after the define line and seeing if the script does exit.
As I said to Marc, I tried echo at the top of both files to see what came first. It came in the right order. It seems that it might just have been empty line at the bottom of the PHP file that caused this error. My previous server var CentOS, but now I'm using Ubuntu. But I'm not sure if this has anything to do with this.
Check my comment above. Looks like empty lines at the bottom of the PHP file vas the cultrip. And since you're the only one with an answer, I will grant you the "solved" points :)
1

I just had the exact same problem and solved it by removing underscores from the constant's name. Hopefully this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.