A blog on PHP, JavaScript and more Amit Merchant · August 11, 2020 · ⋆ PHP One is to implement encapsulation which makes the class members available inside of the originating class only i.e. to hide data from the user of the class and can only be modified using public getter and setter methods.
As you can see, the privateMethod is a private method and if we want to access it outside of the class like so, we would get a fatal error.
And that is how you can access a private method of the class. Similarly, you can also access the private properties of the class but the only distinction here is instead of using ReflectionMethod, we’d need to used ReflectionProperty class like so.