Skip to content

Commit aaa05ae

Browse files
AlexeyDsovdovg
authored andcommitted
Merge pull request #182 from DanielPlainview/master
Eval is evil (singleton)
1 parent 51b6af9 commit aaa05ae

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

core/Base/Singleton.class.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ final public static function getInstance(
3131
if (2 < func_num_args()) {
3232
$args = func_get_args();
3333
array_shift($args);
34-
35-
// can't call protected constructor through reflection
36-
eval(
37-
'$object = new '.$class
38-
.'($args['.implode('],$args[', array_keys($args)).']);'
34+
35+
// emulation of ReflectionClass->newInstanceWithoutConstructor
36+
$object =
37+
unserialize(
38+
sprintf('O:%d:"%s":0:{}', strlen($class), $class)
39+
);
40+
41+
call_user_func_array(
42+
array($object, '__construct'),
43+
$args
3944
);
40-
4145
} else {
4246
$object =
4347
$args

0 commit comments

Comments
 (0)