如何阻止php调试输出在svn中提交?

Sea*_*nJA 8 php svn debugging pre-commit-hook

我想阻止调试函数var_dump, print_r, etc...被提交到repo,以便QA可以检查一些事情而不报告诸如"所有页面上都有大量文本!!"之类的错误.

我试过正则表达式(不是一个好主意......大概).

我也试过token_get_all但是由于某种原因,它会返回T_STRING每个调试函数,我想这会起作用,但它看起来很奇怪......

还有第三种更好的方法吗?

Sea*_*nJA 0

根据我的新理解,这就是我所拥有的:

$debug_functions = array('print_r', 'var_dump', 'var_export');

foreach($files as $file=>$ext){
    $file_contents = file_get_contents($file);
    //break the content into tokens
    $tokens = token_get_all($file_contents);
    foreach($tokens as $t){
        //if the token id is an int (sometimes it isn't)
        if(is_int($t[0])){
            //if it matches our debug stuff...
            if($t[0] == T_STRING && (in_array($t[1], $debug_functions) || preg_match('/xdebug_.*?/', $t[1]))){
                echo 'Debug output '. $t[1] . ' found on line '. $t[2] . PHP_EOL;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)