views:

174

answers:

2

IN PHP5 i can declare a const value to a class:

class config
{
     const mailserver = 'mx.google.com';
}

But i can also declare public static:

class config
{
     public static $mailserver = 'mx.google.com';
}

In case of a config file which i will later us, like:

imap_connect(config::$mailserver ...
imap_connect(config::mailserver ...

Which of the option do you think is better to be used?? (faster, less memory load, etc ..)

Thanks.

+13  A: 

The static variable can be changed, the const one cannot. The main consideration should be given to weather the config variables should be able to be altered at run time, not which is faster. The speed difference between the two (if there is any) is so minimal it isn't worth thinking about.

Yacoby
+1  A: 

Also note that because of what Yacoby said above, there are certain things you can do with a static variable you can't do with a CONST, for example assign the result of a runtime method call to the variable.

Keith Humm