Before we answer this question, you must have a clear definition of what exactly is an abstract class, an abstract method and a static method.
Abstract Class: In the Object-Oriented programming paradigm, abstraction refers to the process of hiding the internal implementation details of any program and only showing the functionality of the program to the user. Abstract classes are a way of achieving this. An abstract class is any class that cannot be instantiated (i.e. objects cannot be created) and has to be extended (inherited) for objects to be created. The ‘abstract’ keyword is used to create abstract classes.
Abstract Method: An abstract method is a method that can only be declared and not defined. It is defined in the class that inherits from this class.
Static Method: A static method of any class is a method that is created only once. This means that even if you create hundreds of objects of a class with static methods, there will be the only copy of each static method.
Consider the following example:
Now if you run this PHP code, you will see the error, “PHP Fatal error: Cannot call abstract method Abstract_Parent::X().”
When we call method X() in the child class, the static function X() in the parent gets called. In the method X(), we are again calling function Y(), which is an abstract static function. The Y() that function X() is trying to call is the parent class Y(), which is itself an abstract function.
So, using abstract and static on the same method defeats each other purpose. This is the reason why PHP 5.2+ does not allow abstract static class methods.
- Abstract Methods in Java with Examples
- Understanding "static" in "public static void main" in Java
- Difference between static and non-static method in Java
- Difference between static and non-static variables in Java
- Abstract Classes in PHP
- C# | Abstract Classes
- Abstract Classes in Python
- Scala | Abstract Type members
- Messages, aggregation and abstract classes in OOPS
- New self vs. new static in PHP
- How to find the parent class name with known class in jQuery ?
- Static Function in PHP
- Difference between self::$bar and static::$bar in PHP
- What is Late Static Bindings in PHP ?
- How to create static classes in PHP ?
- Static vs Dynamic Website
- When to use static vs instantiated classes in PHP?
- Ruby Static Members
- Difference between Static and Shared libraries
- Comparison between static and instance method in PHP