PHP - 创建一个名为 'Default' 的 class
PHP - Creating a class named 'Default'
我知道 default 是 PHP 中的保留关键字。我遇到了这种奇怪的情况,我想将我的 class Default 命名为,但似乎每当我尝试在代码中的任何地方创建它时,我的整个页面都会变成空白并且PHP 没有显示任何错误。这真的很令人困惑,我花了 20 多分钟在我的代码中搜索问题。因为我对此很恼火,所以我想知道这有什么问题。
(我试过不同的命名空间,但还是一样的效果,例如:)
new \SomeNamespace\Default();
有人可以为我解释为什么会发生这种情况并且没有出现任何错误吗?这只是我们必须忍受的 PHP 缺陷吗?
http://php.net/manual/en/reserved.keywords.php
These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on - but they're not, really: they are language constructs. You cannot use any of the following words as constants, class names, function or method names. Using them as variable names is generally OK, but could lead to confusion.
根本不不不。无论您的脚本是否输出错误,都是不可能的。尝试用更有意义的名词来命名您的 class。
我知道 default 是 PHP 中的保留关键字。我遇到了这种奇怪的情况,我想将我的 class Default 命名为,但似乎每当我尝试在代码中的任何地方创建它时,我的整个页面都会变成空白并且PHP 没有显示任何错误。这真的很令人困惑,我花了 20 多分钟在我的代码中搜索问题。因为我对此很恼火,所以我想知道这有什么问题。
(我试过不同的命名空间,但还是一样的效果,例如:)
new \SomeNamespace\Default();
有人可以为我解释为什么会发生这种情况并且没有出现任何错误吗?这只是我们必须忍受的 PHP 缺陷吗?
http://php.net/manual/en/reserved.keywords.php
These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on - but they're not, really: they are language constructs. You cannot use any of the following words as constants, class names, function or method names. Using them as variable names is generally OK, but could lead to confusion.
根本不不不。无论您的脚本是否输出错误,都是不可能的。尝试用更有意义的名词来命名您的 class。