PHP abstract properties

前端 未结 9 1443
终归单人心
终归单人心 2020-12-07 16:16

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

abstract class Foo_Abstract {
    abstract public $tablename;
}

class Foo extends Foo_Abstract          


        
9条回答
  •  一个人的身影
    2020-12-07 16:58

    There is no such thing as defining a property.

    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.

提交回复
热议问题