首页 > Web开发 > 详细

php使用魔法函数和不使用魔法函数比较

时间:2015-07-30 00:28:01      阅读:278      评论:0      收藏:0      [点我收藏+]
/**
* use magic 0.31868386268616s
* not use magic 0.11876797676086s
*/
class Test {
    private $varstr = "123";

    function __get($name) {
        return $this->varstr;
    }
}

function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

$time_start = microtime_float();

$i = 0;
while ($i<100000) {
    $i++;
    $t = new Test();
    $t->varstr;
}

$time_end = microtime_float();
$time = $time_end - $time_start;

echo "Did nothing in $time seconds\n";

建议尽量少用PHP魔法函数

php使用魔法函数和不使用魔法函数比较

原文:http://www.cnblogs.com/gide/p/4687744.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!