What does the PHP error message Notice: Use of undefined constant mean?
department
is meant to be a string (to be used here as array key). Strings in PHP must be enclosed in quotes. In the days of the long past PHP was lax about using quotes for single-word strings but these days are long gone.
Therefore, it must be 'department'
or "department"
.
The same goes for the other errors as well.
As is, it was looking for constants called department
, name
, email
, message
, etc. When it doesn't find such a constant, PHP (bizarrely) interprets it as a string ('department', etc) but warns you about that. Obviously, this can easily break if you do defined such a constant later (though it's bad style to have lower-case constants).
Undefined constant error in php 7.2
This is a common warning that occurs whenever PHP has detected the usage of an undefined constant.
Here is an example of constant being defined in PHP:
define('PI', 3.14);
Below is a list of some cases that might cause the issue:
Forgetting to use a $ symbol at the start of a variable name.
$name = "Aniket";
echo name; // forgot to add $ before nameThe above code will throw: Notice: Use of undefined constant name – assumed ‘name’. Because there is no dollar sign in front of the variable “name”, PHP assumes that I was trying to reference a constant variable called “name”.
Forgetting to place quotes around strings.
echo $_POST[email];
In the example above, I failed to place quotes around the
$_POST
variable“email”
. This code will throw: Notice: Use of undefined constant name – assumed ’email’.To fix this, I’d obviously have to do the following:
echo $_POST["email"];
According to Deprecated features in PHP 7.2.x you should not use undefined constants because:
Unquoted strings that are non-existent global constants are taken to be strings of themselves.
This behaviour used to emit an E_NOTICE, but will now emit an E_WARNING. In the next major version of PHP, an Error exception will be thrown instead.
You can prevent this E_WARNING
only if you declare the constant value before using it.
In the above question, MODULE_HEADER_SELECT_TEMPLATE_STATUS
is not defined.
Related Topics
How to Change PHP Version in Xampp
Convert Svg Image to Png With PHP
Php Json String, Escape Double Quotes for Js Output
How to Enable the Mysqli Extension in PHP 7
How to Convert Text to Svg Paths
How to Fix Undefined Offset: 0 in Laravel Blade
Remove Country Code from Phone Number
How to Convert a 13 Digit Unix Timestamp to Date and Time
Laravel How to Return Single Column Value Using Query Builder
How to Delete Multiple Redis Keys With the Same Pattern in PHP Using Phpredis
How to Remove Duplicate Rows in Laravel
Character Encoding for French Accents
How to Pass Something With Apostrophe to Json
Fatal Error: Call to Undefined Function Sqlsrv_Connect()
Laravel Storage Link Won't Work on Production