PHP抽象属性 [英] PHP abstract properties

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

问题描述

有什么方法可以在PHP中定义抽象类的属性吗?

Is there any way to define abstract class properties in PHP?

abstract class Foo_Abstract {
    abstract public $tablename;
}

class Foo extends Foo_Abstract {
    //Foo must 'implement' $property
    public $tablename = 'users';   
}

推荐答案

没有定义属性的事情.

您只能声明属性,因为它们是初始化时保留在内存中的数据容器.

You can only declare properties because they are containers of data reserved in memory on initialization.

另一方面,可以在不定义函数(缺少函数体)的情况下声明函数(类型,名称,参数),因此可以将其抽象化.

A function on the other hand can be declared (types, name, parameters) without being defined (function body missing) and thus, can be made abstract.

摘要"仅表示已声明但未定义的内容,因此在使用它之前,您需要先定义它,否则它将变得无用.

"Abstract" only indicates that something was declared but not defined and therefore before using it, you need to define it or it becomes useless.

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

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