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) ; //作用就是语义化 方便程序的可读性提高。
原文地址:https://www.cnblogs.com/sharecorner/p/6126576.html