PHP 5构造函数_construct无法正常工作 [英] php 5 constructor _construct does not work
问题描述
我们有php 5.3.0,我想使用构造函数_construct. 但是以某种方式在构造类的实例时不会调用此构造函数. 另一方面,旧的构造函数(函数ClassName())也可以工作. 新版本(_construct)不能与php 5.3.0一起使用吗?
We have php 5.3.0 and I would like to use the constructor _construct. But somehow this constructor is not called when an instance of the class is made. And old constructor ( function ClassName() ) on the other hand works. Should not the new version (_construct) work with php 5.3.0 ?
另一件事,我想用参数构建一个构造函数. 但是父构造函数没有.如果我尝试构建此php,则会告诉我构造函数必须具有与父构造函数相同的结构.是这样吗?
Another thing I would like to build an constructor with arguments. But the parent constructor has none. If I try to build this php tells me the constructor has to have the same construct like the parent constructor. Is this so ?
示例:
abstract class Foo{
function _construct(){
}
}
class Bar extends Foo{
function _construct($arg){
parent::_construct();
}
}
感谢您的回复
推荐答案
__construct()
(两个下划线)
第二个问题:修复__construct()
中的下划线,看看是否仍然存在问题.
Second question: fix the underscores in __construct()
and see if this is still a problem.
这篇关于PHP 5构造函数_construct无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!