简体   繁体   English

在php中,我们可以从类外部访问final类的私有方法吗?

[英]In php can we access private methods of final class from outside the class?

I have a final class along with its private/public static methods in one file and want to access its private static method in another file. 我在一个文件中有一个最终类及其专用/公共静态方法,并想在另一个文件中访问其专用静态方法。 Can I do that? 我可以那样做吗? Is this legal access? 这是合法途径吗?

You could always try altering it at runtime via reflection 您总是可以尝试在运行时通过反射对其进行更改

$method = new ReflectionMethod('FinalClassName', 'staticMethodName');
$method->setAccessible(true);

$method->invoke(null, $arg1, $arg2, $etc);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM