为什么我的构造函数仍然调用,即使类和构造函数的情况不同吗? [英] Why is my constructor still called even if the class and constructor case are different?
本文介绍了为什么我的构造函数仍然调用,即使类和构造函数的情况不同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很惊讶为什么当我们有不同的类和构造函数名称时,构造函数被调用。构造函数名以小r开头?
I am surprised for why the constructor is called when we have different class and constructor name. Constructor name is starting with small "r"?
class Registration{
function registration(){
echo "Constructor is called.";
}
}
$obj = new Registration();
//$obj->registration();
输出:
调用构造函数。
Outputs: Constructor is called.
修改:
这种不区分大小写的行为取决于我们使用的php版本?
Modification: Does this case-insensitive behavior depends on php versions we are using?
推荐答案
php不区分大小写(有时候)。
php is case-insensitive (sometimes). The following would work as well:
CLASS REGISTRATION {
FUNCTION reGISTration(){
ECHO "constructor is called.";
}
}
$obj = NEW Registration();
这篇关于为什么我的构造函数仍然调用,即使类和构造函数的情况不同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文