PHP之const

<?php
    //类常量: 没有访问修饰符。一旦定义不能更改; 直接用类名::类常量 访问。 全局变量。;将特定的常量语义化。更有逻辑的计算,速度快。

    class Test{
        //定义常量
        const GENDER_MEAL=1;
        const GENDER_FEMEAL=2;
        const GENDER_SERCRT=3;

        public function setGender($g){
            ...
        }
    }

    $test = new Test();

    $test->setGender(Test::GENDER_FEMEAL) ; //作用就是语义化 方便程序的可读性提高。

 

posted @ 2016-12-02 17:27  被时光移动的城市  阅读(846)  评论(0编辑  收藏  举报