Open In App

Abstract Classes in PHP

Abstract classes are the classes in which at least one method is abstract. Unlike C++ abstract classes in PHP are declared with the help of abstract keyword. Use of abstract classes are that all base classes implementing this class should give implementation of abstract methods declared in parent class. An abstract class can contain abstract as well as non abstract methods.




<?php
  
// Abstract class example in PHP
abstract class base
{
    // This is abstract function
    abstract function printdata();
      
    // This is not abstract function
    function pr()
    {
        echo "Base class";
    }
}
?>

Following are some important facts about abstract classes in PHP.




Article Tags :