Imagine I have this constant in PHP:
define('APP_PATH', str_replace('//', '/', str_replace('\\', '/', dirname(__FILE__) . '/')));
When I use APP_PATH in my application, does PHP execute the code (dirname, and the two str_replace on __FILE__) each time or PHP execute the code once and store the result in APP_PATH ? I hope I’m clear enough 🙂
This question applies to PHP 5.1.0+.
It should be done once, at the time it was defined.
UPDATED
For documentation: define() – constants
From the documentation:
If you want more information on constants go ahead and read the documentation, it is explained pretty well there and probably has usage examples.