Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

syntax

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');

like image 433
David Fairbanks Avatar asked Feb 19 '23 00:02

David Fairbanks


2 Answers

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

like image 65
raidenace Avatar answered Feb 27 '23 14:02

raidenace


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

like image 20
Ja͢ck Avatar answered Feb 27 '23 12:02

Ja͢ck