PHP 5.1.4 @Linux
Array
(
[direct] => 0.0220710000
[reflection] => 0.0465050000
[difference] => 0.024434
)
Array
(
[direct] => 0.0220710000
[reflection] => 0.0465050000
[difference] => 0.024434
)
<?php
error_reporting(-1);
ini_set('display_errors', TRUE);
setlocale(LC_ALL,'de_DE@euro', 'de_DE', 'de', 'ge');
date_default_timezone_set('Europe/Berlin');
class Combie_DB
{
}
class Combie_Model_User
{
public function __construct(Combie_DB $db)
{
echo 'wurde gerufen<br>';
}
}
function fabrik(Array $registry,$klassenBezeichner)
{
$rc = new ReflectionClass($klassenBezeichner);
$rcconstructorparam=$rc->getConstructor()->getParameters();
$params = array();
foreach($rcconstructorparam as $param)
{
$p_class = $param->getClass();
if(empty($registry[$p_class->name])) throw new Exception('bad Param');
$params[] = $registry[$p_class->name];
}
return $rc->newInstanceArgs($params);
}
$registry = array();
$registry['Combie_DB'] = new Combie_DB('blabla');
$die_neue = fabrik($registry,'Combie_Model_User');
?>
<hr>
<pre>
<?php
var_export($die_neue);
?>
</pre>
Comment