Reputation: 9583
I have some constants defined in a file like:
define("staff", 20);
define("manager", 30);
define("director", 40);
they are not inside a class so
$class = new ReflectionClass("Foo");
$constants = $class->getConstants();
will not help.
Unfortunately the names are not prefixed like PERMISSION_
So the best option for me is to get_defined_constants();
from the current file only
is this possible?
Upvotes: 1
Views: 622
Reputation: 4456
This can be done through get_defined_constant() method. Following will be the code to get those values.
include("/path_to_file/constant_file.php");
$constant_set = get_defined_constants(true);
echo $constant_set['user']['staff'];
echo $constant_set['user']['manager'];
echo $constant_set['user']['director'];
The working script with url: http://sugunan.net/demo/const.php
Upvotes: 3