从类中获取函数结果

时间:2015-12-31 04:46:56

标签: php function class

我在一个类中有一个函数,我想得到这个函数的结果,如:

  

返回的危险函数是:dl,system

这是我的代码

public final function filterFile(){

$disabled_functions = ini_get('disable_functions');

$disFunctionsNoSpace = str_replace(' ', '', $disabled_functions);

$disFunctions = explode(',', $disFunctionsNoSpace);

$this->disFunctions = $disFunctions;

// get file content of the uploaded file (renamed NOT the temporary)
$cFile = file_get_contents($this->fileDestination, FILE_USE_INCLUDE_PATH);


$found = array();

foreach($this->disFunctions as $kkeys => $vvals)
{            
    if(preg_match('#'.$vvals.'#i', $cFile))
    {                  
        array_push($found, $vvals);

    } 
} // end foreach

} // end filterFile

// calling the class
$up = new uploadFiles($filename);

$fileterringFile    = $up->filterFile();

print_r($fileterringFile);
var_dump($fileterringFile);

编辑:为错误添加2个函数:

// check if any uErrors
public final function checkErrors(){

    $countuErrors = count($this->uErrors);

    if((IsSet($this->uErrors) && (is_array($this->uErrors) && ($countuErrors > 0))))
    {
        return true;            
    }
        return false;
} // end checkErrors()


// print user errors
public final function printErrors(){

    $countuErrors = count($this->uErrors);

    if((IsSet($this->uErrors) && (is_array($this->uErrors) && ($countuErrors > 0))))
    {

        echo '<ul>';
        foreach($this->uErrors as $uV)
        {       
            echo '<li>';
            echo $uV;
            echo '</li>';
        }
        echo '</ul>';
    }                
} // end printErrors()

提前致谢

1 个答案:

答案 0 :(得分:0)

在结束filterFile的末尾,添加:

return 'Returned dangerous functions are: '.implode(',',$found);