在a.php 中
if(condition){
include("b.inc");
b_obj = new b();//this call is not made
b_obj->a();
}
在b.inc 中
class b {
function b(){ //constructor
//stmts
}
function a(){
//stmts
}
}
我在php中有这段代码,现在b类的构造函数没有从其他文件中调用,尽管包括了文件?请帮助在其他文件中实现构造函数的调用。
将构造函数更改为__construct(),这是PHP 5及以后版本中的默认构造函数。
您可以更改权限级别,将类/函数设置为"public",然后尝试
或
尝试将"b.inc"文件重命名为"b.php"
最后在b_obj变量之前添加$sign
b_obj = new b();
b_obj->a();
应该是
$b_obj = new b();
$b_obj->a();