码迷,mamicode.com
首页 > 其他好文 > 详细

class constants

时间:2015-05-04 15:22:48      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

Constants differ from normal variables in that you don‘t use the $ symbol to declare or use them.

 

<?php
class MyClass
{
    const constant = constant value;

    function showConstant() {
        echo  self::constant . "\n";
    }
}

echo MyClass::constant . "\n";

$classname = "MyClass";
echo $classname::constant . "\n"; // 自 5.3.0 起

$class = new MyClass();
$class->showConstant();

echo $class::constant."\n"; // 自 PHP 5.3.0 起
?>

 

class constants

标签:

原文地址:http://www.cnblogs.com/iMirror/p/4476140.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!