39

Is this just a stylistic difference, or does using require_once('filename.php') vs require_once 'filename.php' have actual load/efficiency differences?

Ivar
  • 6,138
  • 12
  • 49
  • 61
ina
  • 19,167
  • 39
  • 122
  • 201
  • Just an extra character to type in the case of parentheses. – bcosca Aug 03 '10 at 08:33
  • I'm getting different behaviour for the two. One path is written using dirname and another works relative to the site root. Very odd. – James P. Aug 23 '13 at 01:38

5 Answers5

38

Pear Coding Standards say :

"include_once and require_once are statements, not functions. Parentheses should not surround the subject filename."

Source : http://pear.php.net/manual/en/standards.including.php

Arthur Lacoste
  • 854
  • 1
  • 11
  • 10
20

It's exactly the same thing. It's a matter of style.

The parentheses may get in the way some times. For instance, this example from the manual doesn't do what you expect:

if (include('vars.php') == 'OK') {
    echo 'OK';
}

See example #4.

Artefacto
  • 96,375
  • 17
  • 202
  • 225
  • 7
    But this is not caused by the parentheses. – Gumbo Aug 03 '10 at 05:57
  • I think you should include in the answer what it really does. `('vars.php') == 'OK'` is interpreted as the argument to `include` like in `if (include(('vars.php') == 'OK')) {`. That's why you should avoid using parentheses so it doesn't bring you to the wrong conclusion. – PhoneixS Apr 01 '22 at 11:36
12

What does your heart tell you?

Performance difference, if any: negligible.

Mchl
  • 61,444
  • 9
  • 118
  • 120
7

There is no difference. I don't use the brackets 'cause they are not necessary. require_once is no function.

dst
  • 1,770
  • 13
  • 26
1

include, include_once, require and require_once are not functions, they are statements, that is why you should not use ().

Also, consider this from php.net:

<?php

// won't work
if (include('vars.php') == TRUE) {
    echo 'OK';
}

// works
if ((include 'vars.php') == TRUE) {
    echo 'OK';
}

?>
kintsukuroi
  • 1,332
  • 16
  • 15