5 PHP致命错误:未捕获ArgumentCountError(找不到)

时间:2019-09-14 作者:Aaron Riddle

我最近将WordPress站点从PHP5迁移到PHP7。我们的一个自定义文件列表功能(从服务器目录上的文件夹输出文件列表)在PHP7上的新服务器上失败。我知道存在争论冲突,但我不知道如何纠正它。

The error:

5 PHP致命错误:Uncaught ArgumentCounter错误:函数printDirectory()的参数太少,传入了3个/nas/content/live/lfccedu/wp-content/plugins/lfcc/lfcc。第1026行的php和/nas/content/live/lfccedu/wp-content/plugins/lfcc/lfcc中的4个。php:1014\\n堆栈跟踪:\\n#0/nas/content/live/lfccedu/wp-content/plugins/lfcc/lfcc。php(1026):打印目录(\'https://lfccedu...\', \'/nas/内容/li…\',\'文件/文档…\')\\n#1/nas/内容/直播/lfccedu/wp内容/插件/lfcc/lfcc。php(973):printDirectory(\'https://lfccedu...\', \'/nas/内容/li…\',\'文件/文档…\',\'ASC“)\\n#2[内部函数]:目录列表(Array,,\'lfcc\\u directory\\uu…\')\\ n#3/nas/content/live/lfccedu/wp includes/shortcode。php(325):call\\u user\\u func(\'DirectoryList\',Array\',\'lfcc\\u directory…\')\\n#4[内部函数]:do\\u shortcode\\u tag(Array)\\n#5/nas/content/live/lfccedu/wp includes/shortcode。php(199):preg\\u replace\\u回调(\'/\\\\[(\\\\[?)(captio…,“do\\u shortcode\\u ta…,”[标题id=“at…”)\\n#6[内部函数]:do\\u shortcode(“[标题id=“at…in/nas/content/live/lfccedu/wp content/plugins/lfcc/lfcc.php,第1014行

Here\'s the code:

function DirectoryList($atts)
{
    extract(shortcode_atts( array(
        \'file_root\' => \'\',
        \'folder\' => \'\',
        \'sort\' => \'ASC\'
    ), $atts ));

    $protocol = ((!empty($_SERVER[\'HTTPS\']) && $_SERVER[\'HTTPS\'] != \'off\') || $_SERVER[\'SERVER_PORT\'] == 443) ? "https://" : "http://";
    $domain = $_SERVER[\'HTTP_HOST\'];
    return printDirectory($protocol . $domain, $file_root, $folder, $sort);
}

add_shortcode(\'lfcc_directory_list\', \'DirectoryList\');

function ScheduleUpdateTime()
{
    $aSettings = get_option(\'lfcc_external_db_settings\');
    $sDateTime = (time() < strtotime(date("Y-m-d ".$aSettings[\'cache_time\'],time()))) ? date("Y-m-d",(time()-(60*60*24))) : date("Y-m-d",time());
    $sDateTime .= \' \' . $aSettings[\'cache_time\'];
    return date(\'M j, Y, \\a\\t g:i a\', strtotime($sDateTime));
}

add_shortcode(\'lfcc_last_schedule_update\', \'ScheduleUpdateTime\');

function getFileList($root, $sort)
{
    $files = array();
    if (is_dir($root))
    {
        if ($handle = opendir($root)) 
        {
            while (false !== ($entry = readdir($handle))) 
            {
                if ($entry != "." && $entry != "..") {
                    $files[] = $entry;
                }
            }
        }
        natsort($files);
        if ($sort == \'DESC\')
        {
            $files = array_reverse($files);
        }
    }
    return $files;
}

/**
 * Outputs a list of directories and files recursively.
 */
function printDirectory($url, $root, $path, $sort) 
{
    $sRtn = \'\';
    $current_dir = $root . \'/\' . $path;
    $files = getFileList($current_dir, $sort);
    foreach ($files as $f) 
    {
        $file_path = $current_dir . \'/\' . $f;
        if (is_dir($file_path)) 
        {
            // If it is a directory, output the directory name and look inside it for more
            $sRtn .= "<strong>" . $f . "</strong><ul>";
            $sRtn .= printDirectory($url, $root, $path . \'/\' . $f);
            $sRtn .= "</ul></li>";
        } 
        else 
        {
            // If it is a file, output a link to the file.
            $info = pathinfo($f);
            $sRtn .= \'<li><a class="icon \' . $info[\'extension\'] . \'" href="\' . $url . \'/\' . $path . \'/\' . $f . \'" target="_blank">\' . $info[\'filename\'] . \'</a></li>\';
        }
    }
    return $sRtn;
} 


1 个回复
最合适的回答,由SO网友:Mike Baxter 整理而成

从错误消息来看,您之前的迭代似乎利用了PHP5的松散特性:

函数printDirectory()的参数太少,传递了3个。。。正好有4个。。。

我看到您使用四个参数定义printDirectory():

第一次调用此函数时,将传递所有四个参数。不幸的是,当您递归地(在函数本身内)调用它时,您只传递了四个函数中的三个。

$sRtn .= printDirectory($url, $root, $path . \'/\' . $f);
尝试在递归调用中传递$sort变量。

相关推荐

Prevent loading of functions

我使用了一个主题,其中包括名为“Sharethis”的服务的共享功能和字体真棒。据我所知,函数是从函数中的以下行加载的。php。TT\\u队列::add\\u css(数组(“//netdna.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css”);TT\\u排队::add\\u js(array(\'https://ws.sharethis.com/button/buttons.js\'));如何使用子函数(因为父函数中的更改将在更新