魔术方法__repr___PHP的魔术常数:__LINE__,__FILE__,__FUNCTION__,__CLASS__和__METHOD__

魔术方法__repr__

Setting constants in PHP is as easy as using the define function, but PHP creates a few constants in every script for you that help mostly for debugging purposes (well, that's generally the only time I use them). These constants are called "magic constants."

在PHP中设置常量与使用define函数一样容易,但是PHP在每个脚本中都会为您创建一些常量,这些常量主要用于调试目的(嗯,通常这是我唯一的一次使用) 。 这些常数称为“魔术常数”。

Magic constants have a funny syntax, placing two underscores before and after the constant's word representation. These are PHP's magic constants:

魔术常量的语法很有趣,在常量的单词表示形式之前和之后都有两个下划线。 这些是PHP的魔术常数:

__LINE__
__FILE__
__FUNCTION__
__CLASS__
__METHOD__

You can imagine how helpful these constants are for debugging...but if you can't:

您可以想象这些常量对调试有多大帮助...但是,如果您不能这样做:

if($sugar == '') { echo('$sugar has no value on line '.__LINE__.' of ['.__FILE__.']'); }

There are also helpful uses for these magic constants:

这些魔术常数也有一些有用的用途:

dirname(__FILE__) // get the directory name of the current script

What do you use them for?

你用它们做什么?

翻译自: https://davidwalsh.name/php-magic-constants

魔术方法__repr__

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值