Sunday 18 August 2019

oop - What is an abstract class in PHP?




What is an abstract class in PHP?



How can it be used?


Answer



An abstract class is a class that contains at least one abstract method, which is a method without any actual code in it, just the name and the parameters, and that has been marked as "abstract".



The purpose of this is to provide a kind of template to inherit from and to force the inheriting class to implement the abstract methods.



An abstract class thus is something between a regular class and a pure interface. Also interfaces are a special case of abstract classes where ALL methods are abstract.




See this section of the PHP manual for further reference.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...