dd

建议官方在Date类加上魔术方法__get

jerry thinkphp 2015年11月19日 收藏
最近写项目用到了内置的Date类,发现在没有__get方法,非常不方便。
建议官方给加上。

由于没有__get 魔术方法,实例化类之后,下面这些形同虚设,非常不方便。
    /**
     * 日期的时间戳
     * @var integer
     * @access protected
     */
     protected $date;

    /**
     * 时区
     * @var integer
     * @access protected
     */
     protected $timezone;

    /**
     * 年
     * @var integer
     * @access protected
     */
     protected $year;

    /**
     * 月
     * @var integer
     * @access protected
     */
     protected $month;

    /**
     * 日
     * @var integer
     * @access protected
     */
     protected $day;

    /**
     * 时
     * @var integer
     * @access protected
     */
     protected $hour;

    /**
     * 分
     * @var integer
     * @access protected
     */
     protected $minute;

    /**
     * 秒
     * @var integer
     * @access protected
     */
     protected $second;

    /**
     * 星期的数字表示
     * @var integer
     * @access protected
     */
     protected $weekday;

    /**
     * 星期的完整表示
     * @var string
     * @access protected
     */
     protected $cWeekday;

    /**
     * 一年中的天数 0-365
     * @var integer
     * @access protected
     */
     protected $yDay;

    /**
     * 月份的完整表示
     * @var string
     * @access protected
     */
     protected $cMonth;

    /**
     * 日期CDATE表示
     * @var string
     * @access protected
     */
     protected $CDATE;

    /**
     * 日期的YMD表示
     * @var string
     * @access protected
     */
     protected $YMD;

    /**
     * 时间的输出表示
     * @var string
     * @access protected
     */
     protected $CTIME;
// 添加__get魔术方法
// 改良Date
    public function __get($name){
        return isset($this->$name)?$this->$name:null;
    }
个人愚见,如有不适当之处,勿喷。
dd