Php itself does not have modifiers similar to C # readonly. it should be implemented through design. php itself does not have modifiers similar to C # readonly. it should be implemented through design.
Reply content:
Php itself does not have modifiers similar to C # readonly. it should be implemented through design.
Isn't the constant enough?
Define (key, value)
Talk is cheap, I will show you the code demo.
Like this:
// 1. first snippetclass HelloSomeOne {const NAME = "PHP technology Daquan"; // todo something else .} // 2. second snippet // not in class body innerconst NAME = "PHP technology Daquan ";
Php does not provide such a function, but in the object-oriented design, it can be implemented through 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, use the _ set/_ get magic functions to achieve better writing performance.
Define can be used in PHP scripts, and const can be used in PHP classes.