Home >Backend Development >PHP Problem >php uses const error
const problem caused by php version
I just encountered a problem, a constant is defined in the class:
const USER = ['aa', 'bb', 'cc'];
There is no error in calling the above constants in a static function in the class. All web pages on the website can be opened normally. When pushed online, the website pages could not be opened normally. Checking the error log found an error:
Arrays are not allowed in class constants
Regarding this error, Baidu found the problem:
After correcting the error and pushing it online, everything returned to normal.
But I was wondering why the local error was not reported. After some debugging, I guessed that it was a PHP version problem, so I used the following function to check the local and online PHP versions:
phpversion()
Check to get the version number. The local version is 5.6.12, and the online version is 5.5.12. Baidu found that version 5.6 has enhancements in constants.
Conclusion:
1. Version constants of 5.6 can be arrays, but version constants before 5.6 cannot be arrays;
2. The different statuses between local and online are caused by different PHP versions.
Recommended tutorial: PHP video tutorial
The above is the detailed content of php uses const error. For more information, please follow other related articles on the PHP Chinese website!