为什么php字符串中的所有单个单词

Dan*_*ill 4 php

所以今天我遇到了这个功能/ bug,我正在努力绕过正在发生的事情.

所以我们都知道在php中:

echo 'hello';
print 'world';
echo gettype('test');
Run Code Online (Sandbox Code Playgroud)

将返回此:

hello
world
string
Run Code Online (Sandbox Code Playgroud)

然而,直到今天我才意识到这一点:

echo hello;
print world;
echo gettype(hello);
Run Code Online (Sandbox Code Playgroud)

将返回此:

hello
world
string
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?在php的编译过程中发生了什么,它将任何单个单词视为字符串?这有名字吗?它有什么用处吗?

小智 7

如果PHP无法通过名称找到函数或常量hello,那么是的,它将其视为字符串.然而,这是不好的做法,甚至被警告:

>php -r 'error_reporting(E_ALL|E_STRICT);echo gettype(blah);'
PHP Notice:  Use of undefined constant blah - assumed 'blah' in Command line code on line 1
Run Code Online (Sandbox Code Playgroud)

因此,故事的寓意是始终error_reporting在PHP中开启(就像你应该总是 use strictuse warningsPerl一样).