In PHP 5, what is the difference between using const
and static
?
When is each appropriate? And what role does public
, pr
So to recap on @Matt great answer:
if the property you need should not be changed, then a constant is the the proper choice
if the property you need is allowed to be changed, use static instead
Example:
class User{
private static $PASSWORD_SALT = "ASD!@~#asd1";
...
}
class Product{
const INTEREST = 0.10;
...
}
Edit: It is important to note that PHP 7.1.0 introduced support for specifying the visibility of class constants.