PHP3 and PHP4 all have classes, but their class definitions are really bad and inefficient, but the data says that PHP5 reconstructs object-oriented support, though not entirely object-oriented, but can be seen.
Last night, idle and bored to get this thing, feel PHP5 added class member permissions keyword is good, but the problem again, it seems that there is no convenient way to define the field getter and setter, the traditional way is defined:
Class A
{
Private $field;
Public Function Get_field () {return $this-> $field;}
Public Function Set_field ($value) {$this->field = $value;}
}
It's easy to implement, but to be honest, it sucks to write a bunch of code for a field.
So I wondered if there was a more convenient way to solve it, and it was easy to define its type limitations.
After a long time (no way, not familiar with it.) ) and finally a class to solve the problem:
Here to implement the getter and setter, but due to the time relationship I did not implement ReadOnly function, in fact, is very simple, is to add an item, logo it can not be rewritten as
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.