If the constant is undefined, returns the 2nd argument.
Additionally, if the 3rd is true
, defines constant:$X
of which value is the 2nd.
Demonstration
define('CONST_X', 'I am CONST_X.');
define('CONST_Y', 'I am CONST_Y.');
var_dump( constant::get('CONST_X') );
var_dump( constant::get('CONST_Y') );
var_dump( constant::get('CONST_Z') );
var_dump( constant::get('CONST_Z', 'No such constant!') );
string(13) "I am CONST_X."
string(13) "I am CONST_Y."
NULL
string(17) "No such constant!"
Just-in-Time define()
define('CONST_X', 'I am CONST_X.');
define('CONST_Y', 'I am CONST_Y.');
var_dump( constant::get('CONST_X') );
var_dump( constant::get('CONST_Y') );
var_dump( constant::get('CONST_Z', 'I am CONST_Z.', true) );
echo 'Hi, ' . CONST_X . "\n";
echo 'Hi, ' . CONST_Y . "\n";
echo 'Hi, ' . CONST_Z . "\n";
string(13) "I am CONST_X."
string(13) "I am CONST_Y."
string(13) "I am CONST_Z."
Hi, I am CONST_X.
Hi, I am CONST_Y.
Hi, I am CONST_Z.