Hey all.
I was hoping that if I were to define constants in a separate namespace, like:
<?php
namespace config\database\mysql;
const HOST = 'localhost';
const USER = 'testusr';
const PASSWORD = 'testpwd';
const NAME = 'testdb';
?>
That I would be able to use __autoload
to automatically include them:
<?php
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. The __autoload
is not called for the constant as it is with classes, leaving me with a Undefined constant
error.
Does anybody know a workaround? Something I am missing.
Some way that I can use to simulate the class __autoload
for constants?
Thanks.