当前位置:编程学习 > php >>

PHP面相对象,写不了。。。。

把下面的方法写成面向对象的怎么写?写成一个类带构造函数的。。类似:

class demo_glob{

private $file;

function __construct($file){

$this->file=$fil;

                                   }

            function (){                                  //在这里接下面那个方法就可以了,我自己写的老不行。                }

 

}

-------------------------------------帮忙把下面写成面向对象------------------

<?php
function glob_file($file){
$glob = glob($file.'\\*');
foreach($glob as $val){
if(is_dir($val)){
$round += glob_file($val);

 }
else{

$round +=filesize($val);
 }

   }
return $round;
      }

echo glob_file('.')/pow(1024,2);
?>

答案:
<?php
class demo_glob
{
    static private $File = '';
    public function __construct ()
    {


    }
    public function __destruct ()
    {


    }
    static public function glob_file ( $file )
    {
        self::$File = $file;
        $globs = array ( );
        $glob = '';
        $Round = 0;
        $globs = self::getGlob ( "php" );
        foreach ( $globs as $glob )
            $Round += self::getIsDir($glob);
        return $Round;
    }
    static private function getGlob ( $Ext )
    {
        return glob ( self::$File . $Ext );
    }
    static private function getIsDir ( $val )
    {
        if ( is_dir ( $val ) )
            return self::glob_file ( $val );
        else
            return filesize ( $val );
    }
}
echo demo_glob::glob_file ( 'C:\VertrigoServ\www\*.' ) / pow ( 1024, 2 );
?>

上一个:strpos() 函数 asp中的instr()在php中如何实现?
下一个:求助PHP 字符串按空格分段,然后重新组合

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,