简体   繁体   中英

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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