TechniqueUse PHP's define() function: <?php define("HI", "Hello World!"); print HI; ?> CommentsThis code defines HI as Hello World by using the define() function. Please note that these are constants, not C-style macros ”only valid scalar data may be represented by a constant. For example, the following will not work: function four() { return 4; } define("HI","four()"); print HI; This code would print "four()" instead of printing "4" (as print four(); would do). It is also possible to check whether a constant has already been defined. The defined() function will help you do so. The two functions in combination enable you to make sure that a library file is included only once (similar to C header file constructs). <?php if (!defined("_MYLIB_INC_")) define("_MYLIB_INC_", 1); else return; // Library functions continue here ?> |