Why does PHP have abstract classes if you can use an interface and traits?

后端 未结 3 991
孤独总比滥情好
孤独总比滥情好 2021-01-31 19:47

Earlier today I was doing research on PHP\'s abstract classes, interfaces, and traits.

As far as I can tell, an abstract class says \"anything using me will be using the

3条回答
  •  春和景丽
    2021-01-31 20:30

    It's a bit like saying if floats exist, why do integers exist, they both serve their own specific purposes, but more importantly a look at the history of PHP will shed some light on this:

    PHP was initially built without any support at all for classes, and over the years more and more has been added to extend the capabilities of PHP as we push it further and further (and arguable play catch up with other OOP based languages)

    PHP 5.0

    2004 - Abstract classes and interfaces introduced

    PHP 5.4

    2012 - Traits introduced

    That's an 8 year break, in that time among other things the need arose to add support for interfaces with implementations, and so the trait was born

提交回复
热议问题