Is defining contants is php version dependent?

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
thabet
Forum Newbie
Posts: 1
Joined: Fri Jun 13, 2008 3:06 pm

Is defining contants is php version dependent?

Post by thabet »

Hi everybody,

I have some classes in one php file that I will use in many other php files. I am facing a problem which is the path to the folder that contains the classes. I get a suggestion to use constants.

I have placed the following line in html_generator_classes.php file:
define("HTML_GENERATOR_CLASSES", dirname(__FILE__)."\html_generator_classes.php");

Then I tried to use it in any require/ include directives in other php files like the following:
include HTML_GENERATOR_CLASSES;

It didn't work! I am getting:
PHP Notice: Use of undefined constant HTML_CLASSES - assumed 'HTML_CLASSES' in ....

I read that defining a constant will make it global and can be used from any php file within the application. Or I might misunderstood the concept of constants?

Can anyone please explain to me what went wrong?

Note: I am using Eclipse 3.3 PDT, and it lists the new defined constant in the project outline, and it is suggested using code assistant (by writing the 1st letter then Ctrl+space). But still I am getting the above mentioned error when testing the file on the IE browser.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Is defining contants is php version dependent?

Post by Christopher »

I am assuming that you did the following to actually include the constant definition:

Code: Select all

include 'html_generator_classes.php';
include HTML_GENERATOR_CLASSES;
(#10850)
Post Reply