By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,160 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

Constant or Variable?

P: n/a
Opinions please. I'd like to hear the pro's and con's of

define('BASENAME',dirname($_SERVER['PHP_SELF']));

or

$basename = dirname($_SERVER['PHP_SELF']);

I know that one pro is that the constant can't be changed which is my
ultimate goal, but I solicit your comments.

--
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Raven wrote:
Opinions please. I'd like to hear the pro's and con's of

define('BASENAME',dirname($_SERVER['PHP_SELF']));

or

$basename = dirname($_SERVER['PHP_SELF']);

I know that one pro is that the constant can't be changed which is my
ultimate goal, but I solicit your comments.


A tiny little 'con' might be that you can do

"long string $basename long string"

with a variable, but you must do

'long string ' . BASENAME . ' long string'

with the constant.

But I really don't think that is important.

A pro is that constants are global: with a variable you must do:

$basename = dirname($_SERVER['PHP_SELF']);

function blah() {
global $basename;

... $basename ...
}

but with a constant you do:

define('BASENAME',dirname($_SERVER['PHP_SELF']));

function blah() {

... BASENAME ...
}

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.