Re: How to store data that doesn't change?
| From: | Ashley Sheridan | Date: | Wed, 15 Sep 2010 12:49:31 +0000 |
| Subject: | Re: How to store data that doesn't change? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-308100@lists.php.net to get a copy of this message | ||
On Wed, 2010-09-15 at 08:46 -0400, Peter van der Does wrote:
> Hi,
>
> How do you people store data that doesn't change, an example of this
> would be the version number of your software. You might want to use it
> through out your program but how to you store it?
>
> As far as I can see there are several options to use this data.
> 1. Global Variable
> 2. Store it in a registry class
> 3. Store it in a named constant.
> 4. Use a function that will return the data (kind of like a regsitry
> class but it's not a class)
>
> Personally I don't like option 1 but what about the other options. Is
> any of them faster then the others. What other pros and cons are there.
>
> --
> Peter van der Does
>
> GPG key: E77E8E98
>
> IRC: Ganseki on irc.freenode.net
> Twitter: @petervanderdoes
>
> WordPress Plugin Developer
> Blog: http://blog.avirtualhome.com
> Forums: http://forums.avirtualhome.com
> Twitter: @avhsoftware
>
I'd go with a constant, for the simple reason that it means the variable
can't and shouldn't change in the execution of the script. The constant
could be within a class or a global, however you prefer. There will be
slightly more memory used in a class, but it avoids the constant from
conflicting with others in the script possibly.
Creating a whole function or class for this does seem a little overkill
probably, so a simple global constant should do the job really.
Thanks,
Ash
http://www.ashleysheridan.co.uk