Ensure the class has a constructor

if there is no constructor (this means a model which does not inherit
from Model) newInstance will throw an exception.
This commit is contained in:
AD7six 2012-01-09 23:38:32 +01:00
parent f4c27e04bc
commit 336c750b7e

View file

@ -138,7 +138,11 @@ class ClassRegistry {
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;
}