php 常量调用常量_关于PHP常量

php 常量调用常量

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

FacebookTwitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/about-php-constants/

php 常量调用常量

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值