Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 263
ina Avatar asked Aug 03 '10 05:08

ina


People also ask

When should I use require_once vs require in PHP?

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.

Should I use require or require_once?

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.

What is the difference between include_once () and require_once () Which one would you use in circumstances where you need to connect to a database and why?

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.

What is the use of require_once in PHP?

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.


1 Answers

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

like image 180
Arthur Lacoste Avatar answered Sep 19 '22 20:09

Arthur Lacoste