What is the role of the interceptor ;? PhpclassComputer {private $ _ name; private $ _ model; private $ _ cpu; privatefunction _ set ($ _ key, $ _ value) {$ this-& gt; $ _ key = $ _ role of interceptor
Private function _ set ($ _ key, $ _ value ){
$ This-> $ _ key = $ _ value;
}
Private function _ get ($ _ key ){
Return $ this-> $ _ key;
}
}
$ Computer = new Computer ();
$ Computer-> _ name = 'Lenovo ';
$ Computer-> _ cpu = 'quad-Core ';
$ Computer-> _ model = 'i7 ';
Echo $ computer-> _ name;
Echo $ computer-> _ cpu;
Echo $ computer-> _ model;
If the _ set and _ get methods are used, the private attributes of the class can be modified using the value assignment outside. what is the difference between setting the attribute to Public, it seems that these two methods are useless.
------ Solution --------------------
Yes. your usage is indeed superfluous.
------ Solution --------------------
Set is not used in that way. you can see other open-source frameworks, especially the Active Record class of some open-source frameworks.
------ Solution --------------------
Object-oriented means to hide data and open interfaces.
It is your business that you do not follow. The program will only listen to you, and the syntax is like this.
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service