I have a file file_to_include.php that contains variable definitions,
define("NAME", "John Doe");
But when I try to include it in my other file, index.php, using
include_once 'file_to_include.php';
and then echo my definition in index.php with
echo NAME;
All I see on the page is NAME, not John Doe.
I think definitions are global, what am I doing wrong?
Maybe wrong path, look what the PHP's
inlcude_pathis look like. PHP'sincludeandinclude_oncewill continue, even the requested file is found or not.You should keep that in mind, that
requireandrequire_oncewill break the execution if the file is not found, in contrast toincludeandinclude_onewill not.The PHP documentation says: