David Fairbanks
David Fairbanks

Reputation: 648

What's the difference between include('file.php') and include 'file.php'

Both include('file.php') and include 'file.php' work and seem to be interchangeable.

Does anyone know if there is any difference between the two syntaxes? Performance? Introduced in a particular version?

I know if you're going to write include $_SERVER['DOCUMENT_ROOT'] . '/file.php'; it would probably look clearer to write include($_SERVER['DOCUMENT_ROOT'] . '/file.php');

Upvotes: 4

Views: 160

Answers (3)

Pong
Pong

Reputation: 1

include('file.php') : calculate the value of ('file.php') firstly,of cause the value is file.php, and then include file.php into current file; include 'file.php' : include file.php into current file directly。 As you see, the result is the same, but the second way is more efficient。

Upvotes: 0

raidenace
raidenace

Reputation: 12836

There is no difference. These are 'language constructs'. Syntactically this means that they can be used with or without braces. An example is echo statement.

echo("hello"); and echo "hello"; are the same

Upvotes: 5

Ja͢ck
Ja͢ck

Reputation: 173562

There's no difference, because include is a language construct that doesn't require parentheses, just like echo.

See also: include - scroll up a little bit

Upvotes: 3

Related Questions