As I understood your question, you wanted to know if you can overload public variables.
You already knew about the __get($name) magic method, right? Or maybe you were talking about getName(), getAge() and *getStatus_Indicator()*.
In any case as public properties you can't tap into the magic methods.
I'll just list them for proof of concept.
Example 1
<?php
class Dummy {
public $name;
public $age;
public $status_indicator;
public function __construct() {
foreach($this AS $name => $value) {
$this->$name = new LazyLoader($this, $name);
}
}
}
class LazyLoader {
protected $object;
protected $name;
public function __construct($object, $name) {
$this->object = $object;
$this->name = $name;
}
public function load() {
/* find the necessary $data somehow */
$name = $this->name;
$this->object->$name = $data;
/*
after the first call to LazyLoader::load
the property no longer points to a LazyLoad
object, but to the intended value
*/
}
public function __toString() {
return($this->load());
}
}
?>
Example 2
<?php
class LazyCollectionWrapper extends ArrayObject {
public function __construct($objects = array()) {
parent::__construct($objects);
}
public function offsetGet($offset) {
$this->collection[$offset]->lazyLoad();
return($this->collection[$offset]);
}
}
class Dummy {
public $name;
public $age;
public $status_indicator;
public function lazyLoad() {
/* load stuff here */
}
}
?>
Example 3
<?php
class Dummy {
public function __get() {
/*
load stuff here because undefined
properties are caught by __get too
*/
}
}
?>
Example 3 is least informative about the structure but as far as memory is concerned it's the best way to do it. We were talking about lazy loading stuf... i.e. not loading useless stuff into memory right?
I say this because:
class x { protected $var1 = array(); protected $var2 = 0.0; }
Eats up more memory than
class x { protected $var1; protected $var2; }
And even more than
class x { }
I've tested it by building millions of objects and comparing peak memory usages.