php uses const error

王林
Release: 2023-02-24 07:20:01
Original
3024 people have browsed it

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'];
Copy after login

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
Copy after login

Regarding this error, Baidu found the problem:

php uses const error

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()
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template