I'm getting the following error in PHP:
Notice: Use of undefined constant CONSTANT
on the exact line where I define it:
define(CONSTANT, true);
What am I doing wrong? I defined it, so why does it say "Undefined constant"?
I'm getting the following error in PHP:
Notice: Use of undefined constant CONSTANT
on the exact line where I define it:
define(CONSTANT, true);
What am I doing wrong? I defined it, so why does it say "Undefined constant"?
You need to quote the string which becomes a constant
define('CONSTANT', true);
If you write it like that you are using the value of an already defined constant as a constant name.
What you want to do is to pass the name as a string:
define('CONSTANT', true);
Although not really, strictly relevant to your case, it is most desirable to first check that a
CONSTANThas not been previously defined before (re)defining it.... It is also important to keep in mind that definingCONSTANTSusingdefinerequires that theCONSTANTto be defined is aSTRINGie. enclosed within Quotes like so:
<?php
// CHECK THAT THE CONSTANTS HASN'T ALREADY BEEN DEFINED BEFORE DEFINING IT...
// AND BE SURE THE NAME OF THE CONSTANT IS WRAPPED WITHIN QUOTES...
defined('A_CONSTANT') or define('A_CONSTANT', 'AN ALPHA-NUMERIC VALUE', true);
// BUT USING THE CONSTANT, YOU NEED NOT ENCLOSE IT WITHIN QUOTES.
echo A_CONSTANT; //<== YIELDS:: "AN ALPHA-NUMERIC VALUE"
See below currect way to define constant
define('Variable','Value',case-sensitive);
Here Variable ==> Define your Constant Variable Name
Here Value ==> Define Constant value
Here case-sensitive Defult value 'false', Also you can set value 'true' and 'false'