简体   繁体   中英

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. 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 .

There's no notable performance differences.

From the PHP docs on echo

echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses.


Both echo and require are language constructs , the same applies to require , include , require_once and include_path .

The parentheses do make a difference. All you need to do is read the fine manual

echo

Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses

include (applies to require as well)

Because include is a special language construct, parentheses are not needed around its argument. Take care when comparing return value.

See Example #4 for how it can make a difference.

I would recommend not using parentheses with either construct due to the limitations they impose ( echo ) and the effect on return values ( include )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM