Home >Backend Development >PHP Tutorial >Teach you to view PHP const_PHP tutorial correctly

Teach you to view PHP const_PHP tutorial correctly

WBOY
WBOYOriginal
2016-07-15 13:33:45912browse

If we encounter a constant value that cannot be changed in actual programming, we usually define a constant to use this constant value. Then at this time we use

When defining a constant, we can use const to modify the constant. The constants modified with PHP const are slightly different from other constants: Do not use "$" before the constant name, remember! Of course, this constant value cannot be modified. Once defined, it cannot be "artificially" modified anywhere in the program. This is the same as using define to define, and using const to define of course also follows the naming rules of other constants - use large letters.

Let’s look at a small example of PHP const:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php   </span></span></li><li><span>class say_const{   </span></li><li class="alt"><span>const </span><span class="attribute">CHARSET</span><span>=</span><span class="attribute-value">"中国"</span><span>;   </span></li><li><span>publice function say_hello(){   </span></li><li class="alt"><span>echo slef::CHARSET;   </span></li><li><span>}   </span></li><li class="alt"><span>}   </span></li><li><span>$</span><span class="attribute">const1</span><span>=</span><span class="attribute-value">new</span><span> say_const()'   </span></li><li class="alt"><span>$const1-</span><span class="tag">></span><span>say_hello();   </span></span></li>
<li>
<span class="tag">?></span><span>   </span>
</li>
<li class="alt"><span> </span></li>
</ol>

The above is an introduction to the specific usage of PHP const.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446024.htmlTechArticleIf we encounter a constant value that cannot be changed in actual programming, we usually define a constant to use this constant numerical value. Then we use it at this time. When defining a constant...
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