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

返回当前类所有常量的Key=>value 集合

时间:2017-11-14 17:15:38      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:php   tco   return   常量   val   str   ant   返回   function   

<?php

class Test
{
    const A = ‘1‘;
    const B = ‘2‘;
    const C = ‘3‘;
    const D = ‘4‘;
    const E = ‘5‘;
    const F = ‘6‘;

    public static function all()
    {
        $static = new static();
        $class = new \ReflectionClass($static);
        $constants = $class->getConstants();
        return $constants;
    }
}

var_dump(Test::all());
//打印结果如下:
//array (size=6)
//  ‘A‘ => string ‘1‘ (length=1)
//  ‘B‘ => string ‘2‘ (length=1)
//  ‘C‘ => string ‘3‘ (length=1)
//  ‘D‘ => string ‘4‘ (length=1)
//  ‘E‘ => string ‘5‘ (length=1)
//  ‘F‘ => string ‘6‘ (length=1)

  

返回当前类所有常量的Key=>value 集合

标签:php   tco   return   常量   val   str   ant   返回   function   

原文地址:http://www.cnblogs.com/spectrelb/p/7833327.html

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