In PHP 5, what is the difference between using const and static?
When is each appropriate? And what role does public, protected and private play - if any?
In PHP 5, what is the difference between using const and static?
When is each appropriate? And what role does public, protected and private play - if any?
One last point that should be made is that a const is always static and public. This means that you can access the const from within the class like so:
class MyClass
{
const MYCONST = true;
public function test()
{
echo self::MYCONST;
}
}
From outside the class you would access it like this:
echo MyClass::MYCONST;