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_path
is look like. PHP'sinclude
andinclude_once
will continue, even the requested file is found or not.You should keep that in mind, that
require
andrequire_once
will break the execution if the file is not found, in contrast toinclude
andinclude_one
will not.The PHP documentation says: