What is the difference between require “path” and require(“path”)?

The following situation took place: a library was installed via PEAR, which was available in any project script via

require "lib_name/lib_class.php";

So, in order to replace it with one of the same name (for example, for debugging), we added it to the project and “regulated” the use of the library from the server or from the project, respectively, using requare with and without brackets.

Accordingly, we conclude (for relative paths):

  • require ("file_name")– searches for file_namefirst in folders from include_path, and then in project folders.
  • require "file_name"– searches first in project folders, then in folders from include_path.

Comment from admin:

did an experiment – I confirm the presence of the specified effect on the version of PHP 5.2.6-1+lenny10 with Suhosin-Patch

I would very much like to receive documentary evidence of this effect from this community 🙂

This effect does not change from build to build of php. And the documentation for C++ prompted the idea of ​​​​different logic for searching for a loaded file (it is officially described in it).

Answer 1, authority 100%

Brackets only. There is no require function in PHP as far as I know. The brackets in this case are just redundant grouping, just like echoand return.


I think, given “it was possible to find out by experience”, the author hints at this garbage (or something like that):

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

But it is generally weakly connected with the subject. Rather, it refers to grouping in boolean expressions.

Answer 2, authority 33%

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


Because include() is special
language construct, brackets
around the argument are not needed. But be
be careful with return value comparison.

The require() page refers to include().

Answer 3

Parentheses are usually used to pass arguments to a function, it’s possible that require has more than one argument, as usually used with one, brackets are omitted.