note 35064 modified in language.constants by danbrown

From: Date: Tue, 26 Jul 2011 20:05:56 +0000
Subject: note 35064 modified in language.constants by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181913@lists.php.net to get a copy of this message
I find using the concatenation operator helps disambiguate value assignments with constants. For example, setting constants in a global configuration file: <?php define('LOCATOR', "/locator"); define('CLASSES', LOCATOR."/code/classes"); define('FUNCTIONS', LOCATOR."/code/functions"); define('USERDIR', LOCATOR."/user"); ?> Later, I can use the same convention when invoking a constant's value for static constructs such as require() calls: <?php require_once(FUNCTIONS."/database.fnc"); require_once(FUNCTIONS."/randchar.fnc"); ?> as well as dynamic constructs, typical of value assignment to variables: <?php $userid = randchar(8,'anc','u'); $usermap = USERDIR."/".$userid.".png"; ?> The above convention works for me, and helps produce self-documenting code. -- Erich --was-- I find using the concatenation operator helps disambiguate value assignments with constants. For example, setting constants in a global configuration file: define('LOCATOR', "/locator"); define('CLASSES', LOCATOR."/code/classes"); define('FUNCTIONS', LOCATOR."/code/functions"); define('USERDIR', LOCATOR."/user"); Later, I can use the same convention when invoking a constant's value for static constructs such as require() calls: require_once(FUNCTIONS."/database.fnc"); require_once(FUNCTIONS."/randchar.fnc"); as well as dynamic constructs, typical of value assignment to variables: $userid = randchar(8,'anc','u'); $usermap = USERDIR."/".$userid.".png"; The above convention works for me, and helps produce self-documenting code. -- Erich http://php.net/manual/en/language.constants.php

« previous php.notes (#181913) next »