Skip to content

Commit

Permalink
Merge remote-tracking branch 'jubianchi/create-object-secure'
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jan 5, 2013
2 parents 054ad95 + acbf982 commit da63267
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Nelmio/Alice/Loader/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,24 @@ private function getGenerator($locale = null)

private function createObject($class, $name, $data)
{
$obj = unserialize(sprintf('O:%d:"%s":0:{}', strlen($class), $class));
try {
$reflector = new \ReflectionMethod($class, '__construct');
$argc = $reflector->getNumberOfRequiredParameters();

if (0 === $argc) {
$obj = new $class();
} else {
if (-1 === version_compare(phpversion(), '5.4')) {
$obj = unserialize(sprintf('O:%d:"%s":0:{}', strlen($class), $class));
} else {
$reflector = new \ReflectionClass($class);
$obj = $reflector->newInstanceWithoutConstructor();
}
}
} catch (\ReflectionException $exception) {
$obj = new $class();
}

$variables = array();
foreach ($data as $key => $val) {
if (is_array($val) && '{' === key($val)) {
Expand Down

0 comments on commit da63267

Please sign in to comment.