如何避免这种假冒"dirname()正好需要1个参数"警告?

Chr*_*sJJ 8 php

在PHP V5.6.13上,

dirname("",1);
Run Code Online (Sandbox Code Playgroud)

Warning: dirname() expects exactly 1 parameter, 2 given
Run Code Online (Sandbox Code Playgroud)

尽管http://php.net/manual/en/function.dirname.php

string dirname ( string $path [, int $levels = 1 ] )
Run Code Online (Sandbox Code Playgroud)

如何避免出现这种虚假警告?

Ign*_*ams 14

升级到PHP 7.

更新日志

Version   Description  
7.0.0     Added the optional levels parameter.  
Run Code Online (Sandbox Code Playgroud)


Tar*_*rik 7

如果您没有PHP 7,请使用下面的函数获取具有级别的递归目录名:

function dirname_r($path, $count=1){
    if ($count > 1){
       return dirname(dirname_r($path, --$count));
    }else{
       return dirname($path);
    }
}
echo dirname_r(__FILE__, 2);
Run Code Online (Sandbox Code Playgroud)