PHP中的抽象关键字 [英] Abstract keyword in PHP

查看:87
本文介绍了PHP中的抽象关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我对PHP很有经验,但是我不知道关键字abstract在面向对象编程时会做什么.谁能用简单的英语解释它的用途?

Hey, I'm quite experienced with PHP but I have no idea what the keyword abstract does when it comes down to object orientated programming. Can anyone explain in plain english what it can be used for?

在什么情况下我应该使用abstract关键字?它如何更改类/接口?

What situations would I use the abstract keyword in? How does it change the class/interface?

推荐答案

(希望这很简单-我认为我不能做得更好^^)

不能实例化abstract类:您只能创建从abstract类继承的另一个类,并实例化该子类.

An abstract class can not be instanciated : you can only create another class that inherits from the abstract class, and instanciate that child class.

如果您将某些方法声明为abstract,则必须在子类中定义这些方法,以使该方法变得不可思议.

And if you declare some methods as abstract, those must be defined in the child class, for that one to be instanciable.

这篇关于PHP中的抽象关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆