<?php
/**
*Abstract Methods and Classes
*An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
*An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:
*abstract void car_details(char model, double price);
*If a class includes abstract methods, then the class itself must be declared abstract, as in:
* public abstract class Cars {
* // declare fields
* // declare nonabstract methods
* abstract void car_details();
* }
* When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract.
* In Abstract class someone can write the definitation and someone can use/extend it, abstract means incomplete.
* It is not possible to create object of abstract method
* abstract class contains atleast 1 abstract function, it can have abstract and non abstract methods.
* abstract function can not contain body or definitation it must declare, but should not have function definitation.
* abstract class, child class must contain abstract function
*/
abstract class Cars
{
abstract function car_details();
}
class Maruti extends Cars
{
function car_details()
{
echo "Maruti Details";
}
}
class Honda extends Cars
{
function car_details()
{
echo "<br>Honda Details<br>";
}
}
class Scoda extends Cars
{
function car_details()
{
echo "<br>Scoda Details<br>";
}
}
$obj = new Maruti();
$obj -> car_details();
$obj1 = new Honda();
$obj1 -> car_details();
$obj2 = new Scoda();
$obj2 -> car_details();
?>
abstract class AbstractFoo{
public static function foo() {
throw new RuntimeException("Unimplemented");
}
public static function getFoo(){
return static::foo();
}
}
class ConcreteFoo extends AbstractFoo{
public static function foo(){
return "bar";
}
}
echo ConcreteFoo::getFoo();
Answer
https://stackoverflow.com/questions/41611058/why-does-php-allow-abstract-static-functions/41611876