- 论坛徽章:
- 0
|
讨论一下php的类
我实验的结果好象不是这样~~不知道是不是我的代码有问题~~~~
其实类封装只不过是一种形式,不论解释语言还是编译语言我觉得在编译器面前不应该有区别。
class test
{
$i;
fuction($a)
{
$i=$a;
}
}
和
$i;
fuction($a)
{
$i=$a;
}
在本质上没有区别~~~
下面是我实验的代码,在我的机器上类的比不用类的多数情况下快~~~
<?php
class test
{
function add()
{
for($c=0;$c<5000000;$c++){
$g=1+1;
}
}
}
$nowtime = explode(" ", microtime());
$starttime = $nowtime[1] + $nowtime[0];
for($c=0;$c<5000000;$c++){
$g=1+1;
}
$nowtime = explode(" ", microtime());
$endtime = $nowtime[1] + $nowtime[0];
$totaltime = ($endtime - $starttime);
echo $totaltime."<br>;";
$nowtime = explode(" ", microtime());
$starttime = $nowtime[1] + $nowtime[0];
$c = new test;
$c->;add();
$nowtime = explode(" ", microtime());
$endtime = $nowtime[1] + $nowtime[0];
$totaltime = ($endtime - $starttime);
echo $totaltime;
?>; |
|