Blogger Information
Blog 5
fans 0
comment 0
visits 10647
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php常量语法
勇往直前
Original
820 people have browsed it

实例

<?php
class Demo
{
	//类常量就是它的值在类中始终保持不变的量
	//用const关键字创建,不加$符,必须初始化
	//php5.3+支持nowdoc语法
	const sitename = <<<'EOT'
php中文网<a href="">www.php.cn</a>
EOT;
	public function getSite()
	{
		return self::sitename;
	}
}
//1.通过类名直接访问类常量
echo '类名::类常量',Demo::sitename,'<hr>';
//2.通过类变量访问
$class = 'Demo';
echo '类变量::类常量',$class::sitename,'<hr>';
//3.通过对象访问
$obj = new Demo();
echo '对象::类常量',$obj::sitename,'<hr>';
//4.对象方法访问
echo $obj->getSite();
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post