Tutorial with a simple fix for the error “PHP Warning: Use of undefined constant (this will throw an Error in a future version of PHP). "
PHP 7.2 & PHP 7.3 bring more stability, flexibility and many new functions, which the old scriptures, Pluginand afraid of WordPress they no longer digest them completely.
When you decide to upgrade your server from PHP 5.x to PHP 7.2 or PHP 7.3, you also need to consider some code compatibility issues. Otherwise, you may encounter errors like:
PHP message: PHP Warning: Use of undefined constant CONSTANT - assumed 'CONSTANT' (this will throw an Error in a future version of PHP)
This error message appears every time in the PHP code an undefined constant is found. Valid in all versions of PHP 7.2 or PHP 7.3.
Table of Contents
[Fixed] PHP Warning: Use of undefined constant (this will throw an Error in a future version of PHP)
For example, if we have:
// constant "
After saving, the error “PHP Warning: Use of undefined constant (this will throw an Error in a future version of PHP)” will disappear.
This error can also occur if you forget to put the "
$” in front of a variable name.
Other errors that may occur after upgrading PHP
Syntax errors: Newer versions of PHP have introduced changes in the language's syntax, and code written for PHP 5.x may not be compatible with newer versions. It is important to check and update any syntax errors before upgrading.
Obsolete or superseded features: Some functions or features used in PHP 5.x may no longer be available in PHP 7.x or may be replaced by others. You need to identify and replace these functions in your code to ensure compatibility.
Data type problems: PHP 7.x introduces stricter handling of data types. Thus, certain errors can occur in code that relies on implicit or coercive data types. It is recommended that you carefully check the data types and manage them accordingly.
Impairment errors: PHP 7.x may remove or deprecate certain deprecated functionality or features. It is important to check and replace these deprecated items with recommended alternatives.