When do/should I use __construct(), __get(), __set(), and __call() in PHP?

后端 未结 10 734
再見小時候
再見小時候 2020-12-05 08:16

A similar question discusses __construct, but I left it in my title for people searching who find this one.

Apparently, __get and __set take a parameter that is the

10条回答
  •  天涯浪人
    2020-12-05 09:07

    They're for doing "clever" things.

    For example you could use __set() and __get() to talk to a database. Your code would then be: $myObject->foo = "bar"; and this could update a database record behind the scenes. Of course you'd have to be pretty careful with this or your performance could suffer, hence the quotes around "clever" :)

提交回复
热议问题