Re: Are constants more efficient than variables that never change?

From: Date: Wed, 16 May 2001 01:50:25 +0000
Subject: Re: Are constants more efficient than variables that never change?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52970@lists.php.net to get a copy of this message
In article <9dsknt$fb1$1@toye.p.sourceforge.net>, noahsw@cyberdude.com ("Noah Spitzer-Williams") wrote: > So my question is should i just do: > > define("myvar", 3); > > OR: > > $myvar = 3; > > does defining it make that much of a difference (if i have several of these > variables that could be defined instead). I'm not sure whether there's a significant difference in memory usage, but IMO the difference in scoping rules is a significant consideration. Constants carry over into functions local scope, while variables must be explicitely passed or declared as global in order to become available in a function's local scope. Which one you consider to be the "convenience" and which you consider the "nuisance" is in the eye of the beholder <g>, but IMO either way it's a very handy/exploitable distinction which you can use to speed up development/debugging time. -- CC

« previous php.general (#52970) next »