Saturday, 15 April 2017

oop - Abstract keyword in PHP



Hey, I'm quite experienced with PHP but I have no idea what the keyword abstract does when it comes down to object orientated programming. Can anyone explain in plain english what it can be used for?



What situations would I use the abstract keyword in? How does it change the class/interface?


Answer



(Hope this is simple enough -- I don't think I can do better ^^ )



An abstract class can not be instanciated : you can only create another class that inherits from the abstract class, and instanciate that child class.



And if you declare some methods as abstract, those must be defined in the child class, for that one to be instanciable.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...