What is the significance of php class properties and methods being private?
按键盘手指磨破皮
按键盘手指磨破皮 2017-09-04 19:32:21
0
2
1421

I see that many attributes are written as private or protected. What is the purpose of this?

I read online that it says to prevent others from modifying it at will, but I don’t understand who the other person is referring to? Are they colleagues in the company?

So if you develop the program by yourself, do you not need to set up privatization? If it is public, it will be simple to write and convenient to call?

按键盘手指磨破皮
按键盘手指磨破皮

reply all (2)
Time丶Out

For example, when developing a WeChat official account, if there is an APPID in it, you should write a private attribute to store it instead of a public one, so that when others call your method, this value cannot be changed

  • reply To be precise, this value cannot be called, but your own class object can be called using $this
    Time丶Out author 2017-09-07 04:43:37
冰泪000

Private method means that external calls are not allowed. It usually performs an operation inside the class. If it is called directly using a class instance, an error will be reported. If it is defined as private, the method will not be visible in some IDE editors.

  • reply I know the role of privatization. What I mean is the actual significance, which are the last two sentences of my question.
    按键盘手指磨破皮 author 2017-09-05 09:50:55
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!