You can use abstract to modify a class or method.
A class modified with abstract indicates that this class is an abstract class, and a method modified with abstract indicates that this method is an abstract method.
Abstract classes cannot be instantiated.
Abstract methods only have method declarations but no implementation content of the method.
abstract abstract class
You can use abstract to modify a class.
A class modified with abstract indicates that this class is an abstract class.
Abstract classes cannot be instantiated.
This is a simple abstract method. If it is instantiated directly, the system will report an error.
<?php //定义一个抽象类 abstract class User { public function __toString() { return get_class($this); } } //实例化这个类会出现错误 echo new User(); ?>The NormalUser in the example below inherits from the User class and can be instantiated.
<?php //定义一个抽象类 abstract class User { public function __toString() { return get_class($this); } } //实例化这个类会出现错误 echo new User(); class NormalUser extends User { } $a = new NormalUser(); echo "这个类" . $a . "的实例"; ?>It makes no sense to set up an abstract class alone. Only with abstract methods can abstract classes have flesh and blood. Abstract methods are introduced below.
abstract abstract method
Use abstract-modified classes to indicate that this method is an abstract method.
Abstract methods only have the declaration part of the method and no method body.
Abstract methods do not have {}, but end with ;.
As long as there is an abstract method in a class, the class must be declared as an abstract class.
Abstract methods must be overridden in subclasses.
The following is an abstract class with two abstract methods, setSal() and getSal(). Used to retrieve $sal employee wages.
<?php abstract class User { protected $sal = 0; //这里定义的抽象方法。 //注意抽象方法没有方法体,而且方法结束使用 ; 号。 abstract function getSal(); abstract function setSal(); //定义它的__tostring方法 public function __toString() { return get_class($this); } } ?>Since the User class cannot be directly inherited, we write a NormalUser class that inherits from the User class. When we write the following code, the system will report an error. This error tells us that there are two abstract methods in the User class and we must override these two methods in the subclass.
<?php abstract class User { protected $sal = 0; //这里定义的抽象方法。 //注意抽象方法没有方法体,而且方法结束使用 ; 号。 abstract function getSal(); abstract function setSal(); //定义它的__tostring方法 public function __toString() { return get_class($this); } } class NormalUser extends User { } ?>The following example rewrites these two methods. Although the content of {} in the method body is empty, it can be regarded as rewriting the method. Pay attention to the parameter names of the overridden method. As long as the number of parameters is the same, it is not required that the parameter names must be the same.
<?php abstract class User { protected $sal = 0; //这里定义的抽象方法。 //注意抽象方法没有方法体,而且方法结束使用;号。 abstract function getSal(); abstract function setSal(); //定义它的__tostring方法 public function __toString() { return get_class($this); } } class NormalUser extends User { function getSal() { } function setSal($sal) { } } //这样就不会出错了。 ?>In lines 19-21 below, the three methods of writing and rewriting will report errors.
Line 19, missing parameters.
20 lines, more parameters.
Line 21, the parameter type is wrong. (This way of writing will be introduced in a later chapter)
If there is an abstract method in a class, the class must be declared as an abstract class.
The following class is not an abstract class. It defines an abstract method and will report an error.
<?php class User { protected $sal = 0; //这里定义的抽象方法。 //注意抽象方法没有方法体,而且方法结束使用;号。 abstract function getSal(); abstract function setSal(); //定义它的__tostring方法 public function __toString() { return get_class($this); } } //这个类中有两个抽象方法,如果这个类不是抽象的。会报错 ?>
Abstract class inherits abstract class
When an abstract class inherits another abstract class, there is no need to rewrite the abstract methods in it.
In an abstract class, the abstract method of the abstract parent class cannot be overridden.
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 rewrite the abstract methods in it.
<?php abstract class User { protected $sal = 0; abstract function getSal(); abstract function setSal($sal); } abstract class VipUser extends User { } ?>
After an abstract class is inherited, the abstract methods in it cannot be overridden.
If rewriting occurs, the system will report an error.
<?php abstract class User { protected $sal = 0; abstract function getSal(); abstract function setSal($sal); } abstract class VipUser extends User { abstract function setSal(); } ?>
Abstract classes inherit abstract classes for the purpose of extending abstract classes.
<?php abstract class User { protected $sal = 0; abstract function getSal(); abstract function setSal($sal); } abstract class VipUser extends User { protected $commision = 0; abstract function getCommision(); abstract function setCommision(); } ?>
In PHP5.1, static abstract methods are supported in abstract classes. In the example below, we see that static abstract methods can be declared. When implementing this method, it must be a static method.
Static abstract methods
In PHP5.1, static abstract methods are supported in abstract classes. In the example below, we see that static abstract methods can be declared. When implementing this method, it must be a static method.
<?php abstract class User { protected static $sal = 0; static abstract function getSal(); static abstract function setSal($sal); } class VipUser extends User { static function getSal() { return self::$sal; } static function setSal($sal) { self::$sal = $sal; } } VipUser::setSal(100); echo "you sal is " . VipUser::getSal(); ?> //这里的抽象方法好像没有问题
Reposted from: http://blog.csdn.net/klinghr/article/details/5212952
The above introduces the PHP class example tutorial: abstract class and abstract method, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

类和方法的概念和实例类(Class):用来描述具有相同的属性和方法的对象的集合。它定义了该集合中每个对象所共有的属性和方法。对象是类的实例。方法:类中定义的函数。类的构造方法__init__():类有一个名为init()的特殊方法(构造方法),该方法在类实例化时会自动调用。实例变量:在类的声明中,属性是用变量来表示的,这种变量就称为实例变量,实例变量就是一个用self修饰的变量。实例化:创建一个类的实例,类的具体对象。继承:即一个派生类(derivedclass)继承基类(baseclass)的

function是函数的意思,是一段具有特定功能的可重复使用的代码块,是程序的基本组成单元之一,可以接受输入参数,执行特定的操作,并返回结果,其目的是封装一段可重复使用的代码,提高代码的可重用性和可维护性。

jQuery是一种经典的JavaScript库,被广泛应用于网页开发中,它简化了在网页上处理事件、操作DOM元素和执行动画等操作。在使用jQuery时,经常会遇到需要替换元素的class名的情况,本文将介绍一些实用的方法,以及具体的代码示例。1.使用removeClass()和addClass()方法jQuery提供了removeClass()方法用于删除

class是python中的一个关键字,用来定义一个类,定义类的方法:class后面加一个空格然后加类名;类名规则:首字母大写,如果多个单词用驼峰命名法,如【class Dog()】。

背景最近针对公司框架进行关键业务代码进行加密处理,防止通过jd-gui等反编译工具能够轻松还原工程代码,相关混淆方案配置使用比较复杂且针对springboot项目问题较多,所以针对class文件加密再通过自定义的classloder进行解密加载,此方案并不是绝对安全,只是加大反编译的困难程度,防君子不防小人,整体加密保护流程图如下图所示maven插件加密使用自定义maven插件对编译后指定的class文件进行加密,加密后的class文件拷贝到指定路径,这里是保存到resource/corecla

Vue报错:无法正确使用v-bind绑定class和style,怎样解决?在Vue开发中,我们经常会用到v-bind指令来动态绑定class和style,但是有时候我们可能会遇到一些问题,如无法正确使用v-bind绑定class和style。在本篇文章中,我将为你解释这个问题的原因,并提供解决方案。首先,让我们先了解一下v-bind指令。v-bind用于将V

在本文中,我们将了解enumerate()函数以及Python中“enumerate()”函数的用途。什么是enumerate()函数?Python的enumerate()函数接受数据集合作为参数并返回一个枚举对象。枚举对象以键值对的形式返回。key是每个item对应的索引,value是items。语法enumerate(iterable,start)参数iterable-传入的数据集合可以作为枚举对象返回,称为iterablestart-顾名思义,枚举对象的起始索引由start定义。如果我们忽

基本的Java类型(boolean、byte、char、short、int、long、float和double)和关键字void通过class属性也表示为Class对象;Class类中booleanisPrimitive():判定指定的Class对象是否表示一个基本类型。包装类和Void类的静态TYPE字段;Integer.TYPE==int.class;Integer.class==int.class;数组类型的Class实例对象:Classclz=String[].class;数组的Clas


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.