I was hoping that if I defined constants in a separate namespace, for example:
namespace config\database\mysql; const HOST = 'localhost'; const USER = 'testusr'; const PASSWORD = 'testpwd'; const NAME = 'testdb';
So that I can use __autoload to automatically enable them:
function __autoload($className) { echo "Autoload: {$className}\n"; $class_file = str_replace('\\', '/', $className) . ".php"; if(file_exists($class_file)) { include $class_file; } } echo config\database\mysql\HOST;
This, however, does not work. __autoload not called for a constant, as is the case with classes, leaving me with an Undefined constant error.
Is there some way I can model the __autoload class for constants?
php const autoload
Atli
source share