Skip to content

Commit

Permalink
Ensure the class has a constructor
Browse files Browse the repository at this point in the history
if there is no constructor (this means a model which does not inherit
from Model) newInstance will throw an exception.
  • Loading branch information
AD7six committed Jan 9, 2012
1 parent f4c27e0 commit 336c750
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Cake/Utility/ClassRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ public static function init($class, $strict = false) {
if ($reflection->isAbstract() || $reflection->isInterface()) {
throw new CakeException(__d('cake_dev', 'Cannot create instance of %s, as it is abstract or is an interface', $class));
}
$instance = $reflection->newInstance($settings);
if ($reflection->getConstructor()) {
$instance = $reflection->newInstance($settings);
} else {
$instance = $reflection->newInstance();
}
if ($strict) {
$instance = ($instance instanceof Model) ? $instance : null;
}
Expand Down

0 comments on commit 336c750

Please sign in to comment.