Home  >  Q&A  >  body text

What is the significance of php class properties and methods being private?

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?

按键盘手指磨破皮按键盘手指磨破皮2573 days ago1457

reply all(2)I'll reply

  • Time丶Out

    Time丶Out2017-09-07 04:42:39

    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
    0
  • Time丶Out

    To be precise, this value cannot be called, but your own class object can be called using $this

    Time丶Out · 2017-09-07 04:43:37
  • 呆呆熊去哪了

    呆呆熊去哪了2017-09-05 09:04:38

    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
    0
  • 按键盘手指磨破皮

    I know the role of privatization. What I mean is the actual significance, which are the last two sentences of my question.

    按键盘手指磨破皮 · 2017-09-05 09:50:55
  • Cancelreply