我很惊讶为什么在我们有不同的类和构造函数名称时调用构造函数.构造函数名称以小"r"开头?
class Registration{
function registration(){
echo "Constructor is called.";
}
}
$obj = new Registration();
//$obj->registration();
Run Code Online (Sandbox Code Playgroud)
输出: 调用构造函数.
修改: 这种不区分大小写的行为是否依赖于我们正在使用的php版本?
php不区分大小写(有时).以下也适用:
CLASS REGISTRATION {
FUNCTION reGISTration(){
ECHO "constructor is called.";
}
}
$obj = NEW Registration();
Run Code Online (Sandbox Code Playgroud)