Is php's 'include' a function or a sta

2019-01-06 21:55发布

There are plenty of examples of both on the web. The php manual says "The include() statement [...]", which seems contradictory - if it's a statement shouldn't it not have parenthesis?

Both of these work:

include('somefile.php');
include 'somefile.php;

So should I or anyone else care?

标签: php include
9条回答
叼着烟拽天下
2楼-- · 2019-01-06 22:46

I believe the only difference is what you want to do.

For example, these two

echo 'Hello World';
echo ('Hello World');

...both print Hello World.

It is just what you want to do, what you feel most comfortable with, and if you're like me, you want to make your script look pretty :D

查看更多
贪生不怕死
3楼-- · 2019-01-06 22:48

include, require, echo, print, and a handful of other keywords are language constructs on their own, rather than function calls, and do not need parentheses. However, some people like to pretend they're function calls and use parentheses anyway. They are identical.

查看更多
Melony?
4楼-- · 2019-01-06 22:51

include is a statement : Explain by following eg

// won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('')
if (include('vars.php') == 'OK') {
    echo 'OK';
}

// works
if ((include 'vars.php') == 'OK') {
    echo 'OK';
}
查看更多
登录 后发表回答