Created
March 19, 2013 13:25
-
-
Save xintron/5196076 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 Foo { | |
public function __construct() { | |
var_dump(get_object_vars($this)); | |
} | |
} | |
class Bar { | |
public function __construct(Array $args) { | |
foreach ($args as $key => $value) { | |
$this->$key = $value; | |
} | |
var_dump(get_object_vars($this)); | |
} | |
} | |
function init($class, $data) { | |
$t = new ReflectionClass($class); | |
$inst = $t->newInstanceWithoutConstructor(); | |
foreach ($data as $key => $value) | |
$inst->$key = $value; | |
$inst->bar = 'bice'; | |
return $inst->__construct(); | |
} | |
$data = array('bar' => 'bice'); | |
$obj1 = init('Foo', $data); | |
$obj2 = new Bar($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hardcore stuff