4-1 减少PHP魔法函数的使用 __get($name)返回私有变量 取执行时间

Posted ADSFASFDA

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了4-1 减少PHP魔法函数的使用 __get($name)返回私有变量 取执行时间相关的知识,希望对你有一定的参考价值。

魔法函数执行时间0.635
<?php

class Test{
    private $var=\'123\';
    public function __get($name)
    {
        return $this->var;
    }

}
function current_time(){
    list($usec,$sec)= explode(\' \',microtime());
    return ((float)$usec+(float)$sec);
}
$_start=current_time();
$i=0;
while ($i<20000){
    $i++;
    $t=new Test();
    $t->var;
}
$_end=current_time();
header(\'Content-Type:text/html;charset=utf\');
echo \'执行时间\'.number_format($_end-$_start,3);
View Code

public直接获取执行时间为

<?php

class Test{
   // private $var=\'123\';
    public $var=\'123\';
 /*   public function __get($name)
    {
        return $this->var;
    }*/

}
function current_time(){
    list($usec,$sec)= explode(\' \',microtime());
    return ((float)$usec+(float)$sec);
}
$_start=current_time();
$i=0;
while ($i<20000){
    $i++;
    $t=new Test();
    $t->var;
}
$_end=current_time();
header(\'Content-Type:text/html;charset=utf\');
echo \'执行时间\'.number_format($_end-$_start,3);
View Code

 

以上是关于4-1 减少PHP魔法函数的使用 __get($name)返回私有变量 取执行时间的主要内容,如果未能解决你的问题,请参考以下文章