Tutorial with a simple solution for the error “PHP Warning: Use of undefined constant (this will throw an Error in a future version of PHP)”.
content
PHP 7.2 & PHP 7.3 bring more stability, flexibility and many new functions, which the old scriptures, plugin-uri and teme de WordPress do not completely digest them.
When you decide to upgrade on the server from PHP 5.X to PHP 7.2 or PHP 7.3, you must also consider some code compatibility. It is very possible to meet otherwise with 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 PHP code there is an indefinite constant. Valid in all versions of PHP 7.2 or PHP 7.3.
[Fix] PHP Warning: Use of undefined constant (this will throw an Error in a future version of PHP)
For example, if we have:
echo $_POST[email];
// constanta “mail
” va trebui definita, iar codul va arata in felul urmator:
echo $_POST["email"];
After rescue, the error “PHP Warning: Use of undefined constant (this will throw an Error in a future version of PHP)” it will disappear.
This error may also appear if you forget to put the symbol “$
” in front of the name of a variable.
Other errors that may occur after PHP upgrade
Syntax errors: Newer versions of PHP have made changes in the syntax of the language, and the written code for PHP 5.x may not be compatible with the new versions. It is important to check and update any syntax errors before you upgrade.
Outdated or replaced functions: Some functions or features used in PHP 5.x may no longer be available in PHP 7.X or be replaced with others. It is necessary to identify and replace these features in your code to ensure compatibility.
Problems of data types: PHP 7.X introduces a stricter management of data types. Thus, certain errors may occur in the code that is based on default or coercive data types. It is advisable to carry out a careful check of data and manage them properly.
Impairment errors: PHP 7.X can remove or depreciate certain outdated features or features. It is important to check and replace these depreciated elements with recommended alternatives.