On PHP V5.6.13,
dirname("",1);
gives
Warning: dirname() expects exactly 1 parameter, 2 given
despite http://php.net/manual/en/function.dirname.php
string dirname ( string $path [, int $levels = 1 ] )
How can I avoid this bogus warning appearing?
Upgrade to PHP 7.
Changelog
Version Description 7.0.0 Added the optional levels parameter.
If you don't have PHP 7, use the function below to have a recursive dirname with levels:
function dirname_r($path, $count=1){
if ($count > 1){
return dirname(dirname_r($path, --$count));
}else{
return dirname($path);
}
}
echo dirname_r(__FILE__, 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With