Is it better to use require_once('filename.php') or require_once 'filename.php';

后端 未结 5 1792
遇见更好的自我
遇见更好的自我 2021-01-01 09:27

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

相关标签:
5条回答
  • 2021-01-01 09:34

    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

    0 讨论(0)
  • 2021-01-01 09:47

    What does your heart tell you?

    Performance difference, if any: negligible.

    0 讨论(0)
  • 2021-01-01 09:47

    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';
    }
    
    ?>
    
    0 讨论(0)
  • 2021-01-01 09:56

    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.

    0 讨论(0)
  • 2021-01-01 09:59

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

    0 讨论(0)
提交回复
热议问题