search
Homephp教程PHP开发Things to note when PHP abstract classes inherit abstract classes

When an abstract class inherits another abstract class, the abstract method of the abstract parent class cannot be overridden in the abstract class. Such usage can be understood as an extension of abstract classes.

The following example demonstrates that when an abstract class inherits from another abstract class, there is no need to override the abstract method.

<?
abstract class User 
{
    protected $sal = 0;  
  
    abstract function getSal();
    abstract function setSal($sal);  
}
abstract class VipUser extends User {
     
}
?>

After an abstract class is inherited, its abstract methods cannot be overridden. If overwriting occurs, the system will report an error.

<?
abstract class User 
{
    protected  $sal = 0;  
  
    abstract function getSal();
    abstract function setSal($sal);
}
abstract class VipUser extends User 
{
    abstract function setSal();
}
?>

Program running results:

Fatal error: Can&#39;t inherit abstract function User::setSal() (previously declared abstract in VipUser) in E:\PH

Conclusion: Abstract classes inherit abstract classes for the purpose of extending abstract classes.

<?
abstract class User 
{
    protected $sal = 0;  
  
    abstract function getSal();
    abstract function setSal($sal);
}
abstract class VipUser extends User 
{
    protected $commision = 0;
    static abstract function getCommision();
    abstract function setCommision();   
}
?>

The above code extends the method of the parent class

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools