Dealing with Private Methods
Learn how to handle private methods introduced in PHP 8.
We'll cover the following...
We'll cover the following...
Handling private abstract methods in traits
Generally, in PHP, we can’t enforce control over an abstract private method in an abstract super class because it will not be inherited. In PHP 8, however, we can define an abstract private method in a trait. This can be used as a use-of-code enforcement mechanism when we’re doing API development where the using class is required to define a specified private method.
Please note that although we can designate an abstract method as private in a PHP 8 trait, trait method visibility can easily be overridden in the class that uses the trait. Accordingly, we will not show any code examples because the effect of a private abstract trait method is exactly the same ...