Home  >  Article  >  Backend Development  >  The difference between const and define

The difference between const and define

WBOY
WBOYOriginal
2016-08-08 09:22:591197browse

1. When using const to define a constant, you can only use scalar initialization; when using define to define a constant, we can use any form of expression to initialize the constant;

2. We can use define in a conditional expression to define a constant , but const is not allowed, for example: defined('DEBUG') or define('DEBUG',true)

3. Const defines a constant that is case-sensitive; define defines a constant through the third parameter to determine whether it is case-sensitive. The third parameter is set to TRUE, indicating case sensitivity;

4. Starting from PHP5.3, const can be used outside the class. In previous versions, const can only be used within the class;

The above has introduced the difference between const and define, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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