NYCPHP Meetup

NYPHP.org

[nycphp-talk] constants vs globals

Dan Cech dcech at phpwerx.net
Fri Feb 20 17:21:53 EST 2004


David Mintz wrote:
> On Fri, 20 Feb 2004, Hans Zaunere wrote:
>>>Heh! Which raises the question, then, how many times to you
>>>need to read a
>>>constant to break even on that up-front expense, as it were,
>>>as compared
>>>to a variable?
>>
>>Heh, now that you mention that, I did say ask.  He didn't know - but we
>>did talk a bit about it and I think I lead the witness to around 4 or 5
> 
> But *parsing* the code that contains constants doesn't cost different from
> parsing code containing variables, or does it? If not, and if the accesses
> are wrapped in "if" blocks, whose execution depends on chance,then you'd
> have to devise some sophisticated benchmarking to simulate the real world
> and discover the answer..... ergo, I think it's time to go get a beer and
> forget this.

Realistically when compared to all of the other possible optimisations 
you could perform, this is pretty low on the list.

Personally I use constants for data which is just that, something which 
is not going to be different depending on the time of day, direction of 
the wind, etc.  Anything else that I need either goes into the 
appropriate class or $GLOBALS['config'].

Dan





More information about the talk mailing list