PHP OOP Abstract class

The class declared with an abstract keyword is called an abstract class.

An abstract class has some special properties.

  1. It can not be initiated, the object of this class can not be created.
  2. it will always be inherent in other classes.
  3. It can contain abstract methods. (Methods declared with abstract keyword and do not have a body)
  4. Abstract is always implemented in the derived class.

Example

abstract class Database{
	public $server="127.0.0.1";
}

class User extends Database{

}
$user= new User();
echo $user->server;
$user->server="100";
echo $user->server;
© 2016 - 2022, All Rights are Reserved.