Constant name must not written as string. The following code works also:
<?php
define(MY_NAME, 'value');
define('ANOTHER_NAME', 'value2');
if(defined('MY_NAME')) {
echo MY_NAME . '<br />';
}
if(defined('ANOTHER_NAME')) {
echo ANOTHER_NAME . '<br />';
}
echo MY_NAME . '<br />';
echo ANOTHER_NAME . '<br />';
?>
Output:
value
value2
value
value2
Tested with:
- PHP 5.3.1 on XAMPP on Windows Vista (local)
- PHP 5.2.42 on Apache 2.0 on Linux (remote)
- PHP 5.2.12 on Apache 2.0 on Linux (remote)
----
Server IP: 69.147.83.197
Probable Submitter: 84.181.213.231
----
Manual Page -- http://www.php.net/manual/en/function.define.php
Edit -- https://master.php.net/note/edit/102273
Del: integrated -- https://master.php.net/note/delete/102273/integrated
Del: useless -- https://master.php.net/note/delete/102273/useless
Del: bad code -- https://master.php.net/note/delete/102273/bad+code
Del: spam -- https://master.php.net/note/delete/102273/spam
Del: non-english -- https://master.php.net/note/delete/102273/non-english
Del: in docs -- https://master.php.net/note/delete/102273/in+docs
Del: other reasons-- https://master.php.net/note/delete/102273
Reject -- https://master.php.net/note/reject/102273
Search -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.