我知道include,isset,require,print,echo,和其他一些人都没有的功能,但语言结构.
其中一些语言结构需要括号,而其他语言结构则不需要.
require 'file.php';
isset($x);
Run Code Online (Sandbox Code Playgroud)
有些有返回值,有些则没有.
print 'foo'; //1
echo 'foo'; //no return value
Run Code Online (Sandbox Code Playgroud)
那么语言结构和内置函数之间的内部差异是什么?
我不断发表如下声明:
我的问题是这些语言结构是什么,更重要的是我们为什么需要它们?
因为echo不是函数,所以在调用它时我们不使用括号.
例:
echo "hello";
Run Code Online (Sandbox Code Playgroud)
而不是
echo ("hello");
Run Code Online (Sandbox Code Playgroud)
如果它是一个函数,它将被强制称为 echo ("hello");
在ASP/Vbscript中,我可以通过以下方式之一调用函数;
call dosomething("x","y","z")
dosomething "x","y","z" notice the missing parathesis
Run Code Online (Sandbox Code Playgroud)
我在PHP中看到的这种无括号语法最接近的是echo.我喜欢跳过括号的能力.
我的问题是,如果有一种方法可以在PHP中编写函数,那么不需要使用括号?