search

Home  >  Q&A  >  body text

What are the benefits of using the __get() method and __set() method instead of setting public properties directly?

Although compared to the PUBLIC attribute, the magic method can control read-only and write-only, but the two magic methods are useful for all private members. If you want to control only some of them, you need to write an If judgment. If this is the case, it is better to set the attribute to PUBLIC directly. So, my question is are there any other benefits to the two magic methods?

小毛小毛2443 days ago1330

reply all(0)I'll reply

No reply
  • Cancelreply