Get the App
SLTechnology News&Howtos  ›  Development  › 

How to treat PHP const correctly

Shulou Source: shulou.com Published: 2022-06-03 04:23:27 09月24日 Update

This article shows you how to treat PHP const correctly. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

If we encounter a constant value that cannot be changed in actual programming, we usually define a constant to use this constant value. So that's when we use PHP const.

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

Look at a small example of PHP const:

< ?php class say_const{ const CHARSET="中国"; publice function say_hello(){ echo slef::CHARSET; } } $const1=new say_const()' $const1->

Say_hello ();? > the above is how to treat PHP const correctly. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Constant that is content place skills values knowledge different concise concise examples big letters letters actual articles times more to make programs articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Apple Linux OPPO Reno macOS