PHP itself does not have a modifier like C # readonly, which should be implemented by design.
Reply content:
PHP itself does not have a modifier like C # readonly, which should be implemented by design.
The constant is not OK?
Define (Key,value)
Talk is Cheap,i would show you the code demo.
Like this:
//1.first snippetclass HelloSomeOne{ const NAME = "PHP技术大全"; //todo something else.}//2. second snippet//not in class body innerconst NAME = "PHP技术大全";
PHP does not provide such a function, but in object-oriented design, it can be implemented by the Set/get method.
class { private $a = null; public function setA($a) { if (null === $this->a) { $this->a = $a; } } public function getA() { return $this->a; }}
For the Set/get method, you can use the __set/__get two magic functions to achieve a better writing effect.
In PHP scripts can be implemented with define, in the PHP class can be implemented with the const