为什么Laravel控制器使用protected修饰也可以正常访问?
protected function advert()
{
try {
$result = $this->systemService->advert ();
return $this->response->array (Response::return (200, '获取成功', $result));
} catch (\Exception $e) {
return $this->response->array (Response::return (0, $e->getMessage ()));
}
}
就算使用反射实例化也不能访问protected修饰的方法吧,laravel源码如下
$constructor = $reflector->getConstructor();
// If there are no constructors, that means there are no dependencies then
// we can just resolve the instances of the objects right away, without
// resolving any other types or dependencies out of these containers.
if (is_null($constructor)) {
array_pop($this->buildStack);
return new $concrete;
}
$dependencies = $constructor->getParameters();
// Once we have all the constructor's parameters we can create each of the
// dependency instances and then use the reflection instances to make a
// new instance of this class, injecting the created dependencies in.
$instances = $this->resolveDependencies(
$dependencies
);
array_pop($this->buildStack);
return $reflector->newInstanceArgs($instances);
开心每一天1111