以下文档中生成的警告消息是文档内所有方法中显示的消息。
警告:count():参数必须是一个数组或一个在C98上实现Countable的对象:在第1198行的C:\ php72 \ pear \ phpDocumentor \ vendor \ twig \ twig \ lib \ Twig \ Extension \ Core.php中警告: count():参数必须是在1198行enter image description here上的C:\ php72 \ pear \ phpDocumentor \ vendor \ twig \ twig \ lib \ Twig \ Extension \ Core.php中实现Countable的数组或对象3}} p>
答案 0 :(得分:0)
好的找到了解决方案。
见链接 https://area51.phpbb.com/phpBB/viewtopic.php?t=52691
更改了core.php文件中的函数
/**
* Returns the length of a variable.
*
* @param Twig_Environment $env
* @param mixed $thing A variable
*
* @return int The length of the value
*/
function twig_length_filter(Twig_Environment $env, $thing)
{
if (is_scalar($thing)) {
return mb_strlen($thing, $env->getCharset());
}
if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
return mb_strlen((string) $thing, $env->getCharset());
}
return count($thing);
}
以下
/**
* Returns the length of a variable.
*
* @param Twig_Environment $env
* @param mixed $thing A variable
*
* @return int The length of the value
*/
function twig_length_filter(Twig_Environment $env, $thing)
{
if (null === $thing) {
return 0;
}
if (is_scalar($thing)) {
return mb_strlen($thing, $env->getCharset());
}
if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
return mb_strlen((string) $thing, $env->getCharset());
}
if ($thing instanceof \Countable || is_array($thing)) {
return count($thing);
}
return 1;
}
答案 1 :(得分:0)
我为解决该错误付出了很多努力,所以我想在这里分享完整的解决方案:更改内容以及如何编辑phar文件:
将此脚本复制到phar文件夹中的文件中,并使用php命令行(在代码中指定选项)运行它:
<?php
//to be run with php -d phar.readonly=Off -f thisFileName
if (ini_get('phar.readonly')==1){
die("\n\nThis script must be run with option -d phar.readonly=Off so that it can write the .phar file\n\n");
}
//the file you want to change
$file = 'vendor/twig/twig/lib/Twig/Extension/Core.php';
//the function in the file you want to change
$oldFunction = '#function twig_length_filter[^{]*[^}]*}#'; //assuming it's still the actual one line function, regex might need updates in the furure
//the replacement function
$newFunction = <<<'funct'
function twig_length_filter(Twig_Environment $env, $thing)
{
if (null === $thing) {
return 0;
}
if (is_scalar($thing)) {
return mb_strlen($thing, $env->getCharset());
}
if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
return mb_strlen((string) $thing, $env->getCharset());
}
if ($thing instanceof \Countable || is_array($thing)) {
return count($thing);
}
return 1;
}
funct;
//access the phar
$p = new Phar('phpDocumentor.phar', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME);
//extract the file
$p->extractTo('./', $file, true);
//return here if you want to check the file first
//return;
//change the function
file_put_contents($file,
$newFile = preg_replace(
$oldFunction,
$newFunction,
file_get_contents($file)
)
);
//update the file
$p[$file] = $file;
//done
echo 'Done. Don\'t forget to delete the "vendor" folder extracted from the phar !';