Of the two functions you proposed, the function is the best choice. But to be rude honest, this is what constants are for:
defined('MAIN_LOGO') || define('MAIN_LOGO','img/mainlogo.jpg');
Suppose you are working on a site that should support multiple languages, then you can just use the same trick:
defined('CLIENT_LOCALE') || define('CLIENT_LOCATE',$whereverYouGetThisFrom); defined('MAIN_LOGO') || define('MAIN_LOGO','img/mainlogo_'.CLIENT_LOCALE.'.jpg'); //if language is EN, mainlogo_EN.jpg will be used, if lang is ES, mainlogo_ES.jpg, etc...
In addition, a constant, once defined, cannot be overridden (the key in the name, of course). Also: since there are still a lot of C-things in PHP that are under the hood, and you noted this performance question, you might be wondering what constants are very similar to C macros, which are much faster than regular function calls, or even C ++ built-in functions (even if they were really compiled as built-in functions).
In any case, if you have a ton of these things that you want to centralize, consider creating a pair of ini files for your project and analyze them on some global object
source share