Some thoughts on variables and constants: a) You can't redefine a constant but can redefine a variable.
b) Constants are autoglobal (like superglobals) so for example: <?php define ('CONSTANT', 'some value'); $variable = 'some value'; function foo() { global $variable; print $variable; print CONSTANT; } foo(); ?> Had we not used global $variable, the $variable would not have been available inside the function. But, the constant is AUTOglobal so it is. Read: Variable Scope: http://www.php.net/variables.scope c) Constants must be scalar values in PHP4, (so not arrays, objects, or resources). d) Constants are cool, variables are cool too. Regards, Philip Olson On Fri, 21 Feb 2003, Chris Corwin wrote: > Help, please -- I've just started looking at my first line of PHP code. > > :) > > > A little background, I am *not really* a programmer: I went to art > school. > > I have taught myself to develop web stuff in another language: Lasso, > but have no training. > > In any case, I am looking through a php script that I've downloaded, > and most of it makes at least some sense to me, but I have come upon: > > <?php > > define('BASE', './'); > include(BASE.'Functions/foo.php'); > ?> > > > Now, like any good lister, I checked the source first: php.net > > <http://www.php.net/manual/en/language.constants.php> says: > > "A constant is a identifier (name) for a simple value. As the name > suggests, that value cannot change during the execution of the script > (except the magic constants which aren't actually constants). A > constant is case-sensitive by default. By convention constant > identifiers are always uppercase. > > [...] > > The scope of a constant is global--you can access it anywhere in your > script without regard to scope." > > > > > So it is apparently *similar*, but not *exactly like* a variable, right? > > Can anyone explain the difference to me? > > A particular question I have is about what this phrase means: > > "The scope of a constant is global--you can access it anywhere in your > script without regard to scope." > > > > When it says "anywhere in your script" does that mean it's available to > "all of PHP"? > > Or it is global to the rest of the file currently being processed, > regardless of namespace, unlike a "normal" variable which might be > unavailable in certain namespaces in the file? > > Also, if anyone knows the subtleties of how any such differences effect > the rest of the script, that'd be wonderful, too. > > > Thanks for any help! > > - me > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php