Reputation: 159
My understanding of require_once is that it would prevent multiple PHP files from requiring the same file again. That does not seem to be the case.
functions.php
function myFunction(){}
middleware.php
require_once("functions.php");
app.php
require_once("functions.php");
require_once("middleware.php");
Fatal error: Cannot redeclare myFunction() (previoiusly declared in functions.php....
Upvotes: 2
Views: 325
Reputation: 8200
I wonder if it is requiring a different functions file. Are app.php and middleware.php in the same folder or a different folder?
My suggestion is whenever you use require
, include
, include_once
, or require_once
, that you always use absolute paths using __DIR__
.
Such as require_once __DIR__.'/path/to/file.php'
Upvotes: 2