0
点赞
收藏
分享

微信扫一扫

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

云竹文斋 2023-02-01 阅读 27

/**
* 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魔法函数



举报

相关推荐

0 条评论