constant
Description
The constant of Miscellaneous for PHP returns the value of a constant.
Syntax
constant(
string $name
): mixedParameters
name
The constant name.
Return
Returns the value of the constant.
Examples
1
<? $name = 'MYCONSTANT'; $value = 100; define($name, $value); $return = constant($name); echo $return;
100
2
<?
define('MYCONSTANT', 100);
echo constant('MYCONSTANT');
100
3
<?
define('MYCONSTANT', 100);
echo MYCONSTANT;
100
4
<?
const MYCONSTANT = 100;
echo constant('MYCONSTANT');
100
5
<? const MYCONSTANT = 100; echo MYCONSTANT;
100
6
<?
interface myinterface
{
const MYCONSTANT = 'some';
}
class myclass
{
const MYCONSTANT = 'test';
}
echo constant('myinterface::MYCONSTANT') . PHP_EOL;
echo constant('myclass::MYCONSTANT');
some test
7
<?
interface myinterface
{
const MYCONSTANT = 'some';
}
class myclass
{
const MYCONSTANT = 'test';
}
$name = 'MYCONSTANT';
echo constant('myinterface::' . $name) . PHP_EOL;
echo constant('myclass::' . $name);
some test