![php 常量调用常量](https://i-blog.csdnimg.cn/blog_migrate/7a7413b38c637d4f3a2179870d0e5207.png)
php 常量调用常量
The reader of the PHP cert guide might be wondering about some aspects of the PHP constants, because the constants section of the book doesn't go into as much detail as it goes for other sections like variables for example.
PHP证书指南的读者可能会想知道PHP常量的某些方面,因为本书的常量部分没有像其他变量(例如变量)那样详细。
1. It's not necassary to name the constants always in upper case. It is, however, a good practice, kind of an unspoken convension. You'll make your code easier to read (and maintain) if you always use upper case.
1.不必总是以大写形式命名常量。 但是,这是一种很好的做法,是一种不言而喻的惯例。 如果您始终使用大写字母,则会使代码更易于阅读(和维护)。
2. You don't have to use double quotes when defining a constant. In fact, when you don't have a reason to use double quotes, always use single quotes, it's better in terms of performance.
2.定义常量时,不必使用双引号。 实际上,当您没有理由使用双引号时,请始终使用单引号,这在性能方面会更好。
En example to illustrate the two points above: < ?php define ('something', 123); echo something; ?>
举例说明上述两点: < ?php define ('something', 123); echo something; ?>
< ?php define ('something', 123); echo something; ?>
3. Constants names are case-sensitive. So the following will not work as expected: < ?php define ('something', 123); echo someThing; ?>
3.常量名称区分大小写。 因此,以下内容将无法正常工作: < ?php define ('something', 123); echo someThing; ?>
< ?php define ('something', 123); echo someThing; ?>
4. You cannot include a constant's value as part of a string as you can do with a variable. Here's an illustration: < ?php $var = 'test'; define ('CONST', 123); echo "testing $var variable"; echo "testing {$var} variable"; echo "testing SOMETHING constant"; echo "testing {SOMETHING} constant"; ?>
This will result in: testing test variable testing test variable testing SOMETHING constant testing {SOMETHING} constant
4.您不能像使用变量那样将常量的值包含在字符串中。 这是一个例子: < ?php $var = 'test'; define ('CONST', 123); echo "testing $var variable"; echo "testing {$var} variable"; echo "testing SOMETHING constant"; echo "testing {SOMETHING} constant"; ?>
< ?php $var = 'test'; define ('CONST', 123); echo "testing $var variable"; echo "testing {$var} variable"; echo "testing SOMETHING constant"; echo "testing {SOMETHING} constant"; ?>
< ?php $var = 'test'; define ('CONST', 123); echo "testing $var variable"; echo "testing {$var} variable"; echo "testing SOMETHING constant"; echo "testing {SOMETHING} constant"; ?>
这将导致: testing test variable testing test variable testing SOMETHING constant testing {SOMETHING} constant
Tell your friends about this post on Facebook and Twitter
在Facebook和Twitter上告诉您的朋友有关此帖子的信息
php 常量调用常量