This will not be a popular answer, but still ...
abstract , interface , private and other keywords borrowed from Java are elements of cult cult programming and do not serve a real purpose in PHP, except to make the author more “serious” and “professional”.
Explanation: these keywords are compile-time contracts that do not affect how your program works, and are intended only to help the compiler ... if you have them. In a compiled language, such as Java or C #, you physically cannot deploy a program that violates a contract, for example. does not implement the abstract method. You just do not compile it. This is a good thing, because you can fix some kinds of errors very quickly, without testing or debugging.
PHP, by contrast, does not have a compiler and performs all contract checks at runtime. This is Bad Thing because you need to test and debug to find contract violations manually. Consider the following:
class Abs { abstract function implementMe(); } if ($_GET['x'] == 'foo') include "GoodClass.php"; if ($_GET['x'] == 'bar') include "BadClass.php";
where "BadClass" extends "Abs" but does not implement the "implementMe" method. This script can be deployed and will work fine until someone calls it "? X = bar" and then bang! - your program suddenly crashes. To make matters worse, this will be a “fatal” mistake, so you won’t even be able to handle it in a reasonable way.
That is, abstract and friends are not only useless, but also very harmful to PHP. Not only do they not help you find errors, but they are also a potential source of even more failures. Stay away.
user187291 Aug 30 2018-11-11T00: 00Z
source share