Reputation: 3093
I need to store the document root to be used across my application
I have two options, would someone please mind explaining what would be quicker and why? Or indeed if there is a better way to achieve this.
define("SITE_ROOT", "/"]);
$_SERVER['DOCUMENT_ROOT']."/path/to/file"
so an include would be created as;
require(SITE_ROOT.'/path/to/file');
require($_SERVER['DOCUMENT_ROOT']."/path/to/file");
Upvotes: 0
Views: 262
Reputation: 59701
To use:
define("SITE_ROOT", "/"); //Typo removed
Is a just a little little bit faster than:
$_SERVER['DOCUMENT_ROOT'] . "/path/to/file"
Since you always concatenate something, is the constant a bit faster. But I think this falls under micro management and I don't think that this is your biggest performance issue in your code.
Even if this would be your "biggest performance issue", even then I would say the difference is so small you can decide, what you want to use and what you think is more readable.
Upvotes: 1
Reputation: 3308
AFAIK there shouldn't be any performance difference (You shouldn't be worrying about this kind of stuff), but this seems way cleaner, readable and especially easier to type:
require(SITE_ROOT.'/path/to/file');
than
require($_SERVER['DOCUMENT_ROOT']."/path/to/file");
Upvotes: 1