I want to lazy load the public data members of a class in PHP. Assume we have the following class:
<?php
class Dummy
{
    public $name;
    public $age;
    public $status_indicator;
}
?>
If $name, $age and $status_indicator were private data members I would lazy load them via their getter methods, but since they are public - I am unclear as to how to lazy load them. Is this possible?
EDIT:
Someone commented that there is a method called __get which might help to solve this issue, but I didn't understand it.
                        
You can use
__getto simulate public members which are really dynamically loaded on first access. When you attempt to access an undefined member of an object, PHP will invoke__getand pass it the name of the member you attempted to access. For example, accessing$x->my_variablewould invoke__get("my_variable")if the class had defined an__get_method.In this example,
$dummy->nameindirectly invokes the getter methodgetName, which initializes a private member named$_nameon first access:You could similarly define and invoke other accessors like
getAge.