Skip to content

Instantly share code, notes, and snippets.

@xintron
Created March 19, 2013 13:25
Show Gist options
  • Save xintron/5196076 to your computer and use it in GitHub Desktop.
Save xintron/5196076 to your computer and use it in GitHub Desktop.
<?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);
@andriijas
Copy link

hardcore stuff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment