ahaha that's funny code.
never thought of that. this one is near to usable one
but I'd hate to write such a construct to get my config.
I would prefer $_SERVER['DOCUMENT_ROOT']./../config/ini.php
As of your previous approach, it's
1. useless
2. wrong.
Case one:
Assume we call it from the /users.php
and our includes folder's path is /includes/
So, we can replace your code
PHP Code:
$root = dirname(__FILE__);
include $root.'/includes/file.php'; //always works
with just
PHP Code:
'includes/file.php';
with same result
verdict: useless
Case two:
Assume we call it from the /news/archive.php
and our includes folder's path is /includes/
in this archive.php we have your code
PHP Code:
$root = dirname(__FILE__);
include $root.'/includes/file.php'; //always works
and "File not found" error
because your $root variable named wrong. it has nothing to do with root as it merely relative path to the calling file and nothing more
verdict: wrong
Bookmarks