Is this just a stylistic difference, or does using require_once('filename.php')
vs require_once 'filename.php'
have actual load/efficiency differences?
The require() function is used to include a PHP file into another irrespective of whether the file is included before or not. The require_once() will first check whether a file is already included or not and if it is already included then it will not include it again.
Require means it needs it. Require_once means it will need it but only requires it once. Include means it will include a file but it doesn't need it to continue.
The only difference between the two is that require and its sister require_once throw a fatal error if the file is not found, whereas include and include_once only show a warning and continue to load the rest of the page.
The require_once keyword is used to embed PHP code from another file. If the file is not found, a fatal error is thrown and the program stops. If the file was already included previously, this statement will not include it again.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With