php,如何创建父对象
我想知道是否可以用 php 创建父对象,我已经尝试过:
new parent::__construct($var);
但它不起作用,并且我在 php 日志中收到以下错误:
(..)PHP 解析错误:语法错误、意外的 T_STRING、期望 T_VARIABLE 或 '$'(..)
I would like to know if there is anyway I can make a parent object with php, I have tried this:
new parent::__construct($var);
but it doesn't work and I get the following error in the php logs:
(..)PHP Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$'(..)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能有效:
This might work:
请参阅 http://uk.php.net/get_parent_class
(但不知怎的,我不明白为什么你会需要这样的东西,但也许这只是我......;-))
see http://uk.php.net/get_parent_class
(But somehow I fail to see why you would need something like that. But maybe that's just me.... ;-))
只需调用父类的构造函数,如下所示:
使用parent::__construct() 调用父类构造函数,因为它在 PHP 中不会自动完成。
Just call the constructor of the parent class like:
Use parent::__construct() to call the parent class constructor since it is not done automatically in PHP.