Alex Rivera | Logout

PHP __get and Private class variables

Asked 2008-11-11T21:11:16.880
9

Assuming one has an abstract base class foo with __get() defined, and a child class bar which inherits from foo with a private variable $var, will the parent __get() be called when trying to access the private $var from outside the class?

Edit
Report

1 Answer

4

Yes. __get() and __set() (and __call() for that matter) are invoked when a data member is accessed that is not visible to the current execution.

In this case, $var is private, so accessing it publicly will invoke the __get() hook.

answered 2008-11-11T21:33:37.927

Your Answer