您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
php底层分析-常量
发布时间:2017-11-24 10:06:01编辑:雪饮阅读()
<?php
class Dog{
public $name='gou';
public function __toString(){
return $this->name;
}
}
$dog=new Dog();
define('dog',$dog);
print_r(dog);
/*
define,值为对象时,会把对象转成标量来存储,需要类有__toString魔术方法返回一个字符串。
*/
define('^_^','xy');
//echo ^_^;
var_dump(defined('^_^'));
echo "<br/>";
echo constant('^_^');
/*
define常量名时检测不严格,像如上特殊字符时候如果echo该常量则报错,而使用
defined来检查常量是否定义则返回true,只能通过constant来读取才正常。
*/
?>
关键字词:php,底层,常量
上一篇:php底层分析-PHP编译特点
下一篇:php底层分析-对象