Created
May 11, 2012 22:01
-
-
Save lstrojny/2662665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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