PHP notice: use of undefined constant
There are four types of PHP error. These errors appear when there is something wrong in the written code. The error might be simple or complex. This four PHP error types are warning error, notice error, parse error and fatal error. On this article we focus on PHP NOTICE ERROR type.

What is PHP notice?
This type of error is very is a minor error, similar to PHP warning error. It doesn’t stop the code from being executed. Sometimes this happens when the compiler or the system is not certain about whether it is actual error or regular code. Most of the time this error shows up when there is undefined variable in the PHP code.
As an example, let us execute the below PHP code.
<?php</code>
$a = "Kodlogs";
echo "$b is best!";
?>
On the above example variable b is called but never been defined before. So, notice error ‘Notice: Undefined variable: …’ will appear.
The outcome for the above code is:
is best!
What is PHP constants?
Constants are special variables that cannot be changed. Unlike variables in PHP, constant names do not have a dollar sign ($) at the beginning. They are automatically global variable when they first define and can be used across the entire script. Constant are used for items that will not change once they are named. Constants created by using define() function. While defining constants constant names should be all uppercase letters. Below shown how constants are defined in PHP.
define(“NEW_CONSTANT”, value);
the value type that you passed to define() can be String, Double/Float, Integer or Boolean.
PHP notice: use of undefined constant
This error shows up when undefined constants called in PHP code. It might be appeared because of missing quotes for strings, missing dollar sign for variables, existence of invalid character in factor names like ‘-‘ , ….
For example:
$try = "Kodlogs"; //Create a simple variable called $try.
echo try; //Printing it out.
On the above example forgetting $ Infront of ‘try’ generates below warning
Notice: Use of undefined constant try
PHP Solution for PHP notice
Below listed are best solutions to avoid PHP notice invalid constant
- Make sure there is no missing quotes for all strings. For example:
echo $_POST[qoutes]; // this like is the wrong way
echo $_POST[‘qoutes’]; // make sure there is a quotes.
- Make sure there is no missing of dollar sign while calling variables. For example:
<?php</code>
$a = "Kodlogs";
echo a;
// there is no a constant. To call a please make sure to write it as $a
?>
- Avoid existence of invalid character in factor names For example:
if (5>$factor-name)
{
echo $factor-name;
// $factor-name written wrongly it should be $factor_name
}
Summery
Warning error, notice error, parse error and fatal error are the four types of errors found in PHP. PHP notice is a minor error. ‘PHP notice: use of undefined constant’ error shows up when undefined constants called in PHP code. It might be happened because of missing quotes for strings, missing dollar sign for variables, existence of invalid character in factor names like ‘-‘ , ….