We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如图,正常情况是不应该这么写的,但是类里面的private方法可以被访问还是让人有点困惑。
The text was updated successfully, but these errors were encountered:
恩. 有道理...
Sorry, something went wrong.
其实PHP可以在运行时更改对象的访问级别, 比如把private改为可以访问. 用反射完全可以做到.
参考一下之前我写的一个简单代码:
$ref = new \ReflectionObject($action); $properties = $ref->getProperties(); foreach ($properties as $propertie) { $pname = $propertie->getName(); if (substr($pname, strlen($pname) - 7) == 'Service') { $propertie->setAccessible(true); $propertie->setValue($action, new ServiceProxy($pname)); } }
目的是把Service的私有或者公有成员变量赋值一个ServiceProxy, 在业务开始调用的时候利用Proxy调用具体的Service.
同问,为啥定义为private可以访问
No branches or pull requests
如图,正常情况是不应该这么写的,但是类里面的private方法可以被访问还是让人有点困惑。
The text was updated successfully, but these errors were encountered: