Dynamic polymorphism in PHP

Is dynamic polymorphism in PHP supported as template classes, or is abstract function and overload / override the only way to use polymorphism in PHP?

+3
source share
4 answers

There is nothing like template classes, but you can achieve very different behaviors when using abstract classes and interfaces, as well as using design patterns such as State, Decorator, Strategy and others.

related: PHP ?

+2

, .

+1

You can use interfaces to add common functions to classes. Of course, you can also override certain functions and extend classes. The most common way that I polymorphize the functionality of my classes begins with a base (template) class and extends it for each fork in the tree of its use.

+1
source

Source: https://habr.com/ru/post/1775878/


All Articles