Skip to content

Instantly share code, notes, and snippets.

@lstrojny
Created May 11, 2012 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lstrojny/2662665 to your computer and use it in GitHub Desktop.
Save lstrojny/2662665 to your computer and use it in GitHub Desktop.
<?php
class Base
{
public $property;
}
class Proxy extends Base
{
private $interceptedProperties = array();
public function __interceptProperties()
{
$class = new ReflectionObject($this);
foreach ($class->getProperties() as $property) {
if ($property->isPublic()) {
$propertyName = $property->getName();
$this->interceptedProperties[$propertyName] = $property->getValue($this);
unset($this->{$propertyName});
}
}
}
public function __set($property, $value)
{
}
public function __get($property)
{
if (array_key_exists($property, $this->interceptedProperties)) {
printf("Lazy loading %s\n", $property);
$this->{$property} = $this->interceptedProperties[$property];
}
}
}
$p = new Proxy();
$p->__interceptProperties();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment