PHP类:通过构造函数分配静态属性
发布时间:2020-12-13 13:14:18 所属栏目:PHP教程 来源:网络整理
导读:类的简化示例: class Table extends TableAbstract{ protected static $tablename; function __construct($str){ $this-tablename = "table_" . $str; $this-insert(); // abstract function }} 当我过去使用这样的类时,我在编写类时直接分配了$tablename.
类的简化示例:
class Table extends TableAbstract{ protected static $tablename; function __construct($str){ $this->tablename = "table_" . $str; $this->insert(); // abstract function } } 当我过去使用这样的类时,我在编写类时直接分配了$tablename.但是这次我希望它由构造函数决定.但是当我调用函数引用$tablename时,变量似乎是空的,当我回显SQL时. 我做错了什么,或者有人建议一种方法来实现我想要的东西? 感谢您的任何意见/答案..
由于属性是静态的,使用Table :: $tablename – 或者self :: $tablename来访问它以隐式引用当前类.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |