diff --git a/framework/base/Formatter.php b/framework/base/Formatter.php index 836b8f04a3..78fdac8cc4 100644 --- a/framework/base/Formatter.php +++ b/framework/base/Formatter.php @@ -121,7 +121,7 @@ class Formatter extends Component $params = [$value]; } $method = 'as' . $format; - if (method_exists($this, $method)) { + if ($this->hasMethod($method)) { return call_user_func_array([$this, $method], $params); } else { throw new InvalidParamException("Unknown type: $format"); diff --git a/framework/db/ActiveRelationTrait.php b/framework/db/ActiveRelationTrait.php index 91df098959..ab06c1646e 100644 --- a/framework/db/ActiveRelationTrait.php +++ b/framework/db/ActiveRelationTrait.php @@ -136,13 +136,13 @@ trait ActiveRelationTrait * Finds the related records for the specified primary record. * This method is invoked when a relation of an ActiveRecord is being accessed in a lazy fashion. * @param string $name the relation name - * @param ActiveRecordInterface $model the primary model + * @param ActiveRecordInterface|BaseActiveRecord $model the primary model * @return mixed the related record(s) * @throws InvalidParamException if the relation is invalid */ public function findFor($name, $model) { - if (method_exists($model, 'get' . $name)) { + if ($model->hasMethod('get' . $name)) { $method = new \ReflectionMethod($model, 'get' . $name); $realName = lcfirst(substr($method->getName(), 3)); if ($realName !== $name) { diff --git a/framework/validators/Validator.php b/framework/validators/Validator.php index 764de66ac7..fac370650b 100644 --- a/framework/validators/Validator.php +++ b/framework/validators/Validator.php @@ -136,7 +136,7 @@ class Validator extends Component { $params['attributes'] = $attributes; - if ($type instanceof \Closure || method_exists($object, $type)) { + if ($type instanceof \Closure || $object->hasMethod($type)) { // method-based validator $params['class'] = __NAMESPACE__ . '\InlineValidator'; $params['method'] = $type;