Re: define constants within functions?

From: Date: Tue, 10 Aug 2004 14:30:29 +0000
Subject: Re: define constants within functions?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-193274@lists.php.net to get a copy of this message
On 11/08/2004, at 12:16 AM, Jay Blanchard wrote:
They should be global already... http://us3.php.net/manual/en/language.constants.php "Like superglobals, the scope of a constant is global. You can access constants anywhere in your script without regard to scope. For more information on scope, read the manual section on variable scope."
Ok, just figured out the problem: <? function test() { define('PET_NAME','Fluffy'); } define('PET_TYPE','Cat'); echo PET_NAME." is a ".PET_TYPE; // fails ?> I didn't activate test() :) <? function test() { define('PET_NAME','Fluffy'); } test(); define('PET_TYPE','Cat'); echo PET_NAME." is a ".PET_TYPE; // works ?> --- Justin French http://indent.com.au

« previous php.general (#193274) next »