Dealing with Private Methods

Learn how to handle private methods introduced in PHP 8.

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.

Get hands-on with 1300+ tech skills courses.