[英]php echo and require syntax
I apologize in advance if this is a needless question. 如果这是一个不必要的问题,我会提前道歉。
I've looked around for syntax on php echo and require functions, and multiple pages have different answers. 我已经四处寻找php echo和require函数的语法,多个页面有不同的答案。 However, each version of the syntax works.
但是,每个版本的语法都有效。
What I want to know is if any of these versions are obsolete, or if one performs slightly better than the other. 我想知道的是,如果这些版本中的任何一个已经过时,或者如果一个版本的性能略好于另一个版本。
<?php echo($variable); ?>
<?php echo $variable ?>
<?php require('file.php'); ?>
<?php require 'file.php'; ?>
I see them with parentheses, without parentheses, with single quotation marks, without.. etc. 我看到它们带括号,没有括号,单引号,没有..等。
Is there a definitive syntax for each one? 每个都有明确的语法吗?
Thank you. 谢谢。
echo
and require
aren't functions
, they're language constructs
which don't require parenthesis
. echo
和require
不是functions
,它们是不需要parenthesis
language constructs
。
There's no notable performance differences. 没有显着的性能差异。
From the PHP docs on echo
来自关于
echo
的PHP文档
echo
is not actually a function (it is a language construct), so you are not required to use parentheses with it.echo
实际上不是一个函数(它是一个语言结构),所以你不需要使用括号。 echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function.echo(与其他一些语言结构不同)的行为不像函数,所以它不能总是在函数的上下文中使用。 Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses.
此外,如果要将多个参数传递给echo,则不能将参数括在括号内。
Both echo
and require
are language constructs , the same applies to require
, include
, require_once
and include_path
. echo
和require
都是语言结构 ,同样适用于require
, include
, require_once
和include_path
。
The parentheses do make a difference. 括号确实有所作为。 All you need to do is read the fine manual
您需要做的就是阅读精细手册
Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses
此外,如果要将多个参数传递给echo,则不能将参数括在括号内
include
(applies to require
as well) include
(也适用于require
)
Because include is a special language construct, parentheses are not needed around its argument.
因为include是一种特殊的语言结构,所以在其参数周围不需要括号。 Take care when comparing return value.
比较返回值时要小心。
See Example #4 for how it can make a difference. 参见示例#4 ,了解它如何产生影响。
I would recommend not using parentheses with either construct due to the limitations they impose ( echo
) and the effect on return values ( include
) 由于它们施加的限制(
echo
)以及对返回值的影响( include
),我建议不要在任何一个构造中使用括号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.