首先我收到警告和致命错误。警告:
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
Run Code Online (Sandbox Code Playgroud)
然后我用break替换了继续,警告就消失了。但即使更换后,致命错误仍然发生。致命错误:
PHP Fatal error: Uncaught Error: Call to undefined function each() in D:\xampp\php\pear\PHPUnit\Util\Getopt.php:80
Stack trace:
#0 D:\xampp\php\pear\PHPUnit\TextUI\Command.php(242): PHPUnit_Util_Getopt::getopt(Array, 'd:c:hv', Array)
#1 D:\xampp\php\pear\PHPUnit\TextUI\Command.php(138): PHPUnit_TextUI_Command->handleArguments(Array)
#2 D:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#3 D:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
#4 {main}
thrown in D:\xampp\php\pear\PHPUnit\Util\Getopt.php on line 80
Fatal error: Uncaught Error: Call to undefined function each() in D:\xampp\php\pear\PHPUnit\Util\Getopt.php:80
Stack trace:
#0 D:\xampp\php\pear\PHPUnit\TextUI\Command.php(242): PHPUnit_Util_Getopt::getopt(Array, 'd:c:hv', Array)
#1 D:\xampp\php\pear\PHPUnit\TextUI\Command.php(138): PHPUnit_TextUI_Command->handleArguments(Array)
#2 D:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#3 D:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
Run Code Online (Sandbox Code Playgroud)
Getopt.php第77-83行
reset($args);
array_map('trim', $args);
while (list($i, $arg) = each($args)) {
if ($arg == '') {
continue;
}
Run Code Online (Sandbox Code Playgroud)
我使用 PHP 8.0.1 和 PHPUnit 9(至少我认为,因为我无法使用命令来检查,并且我在 2 月 7 日之后下载了它)
小智 25
您使用的 PHPUnit 版本可能还不是 PHP 8 的最新版本,请尝试
while (list($i, $arg) = each($args)) {
Run Code Online (Sandbox Code Playgroud)
进入
foreach ($args as $i => $arg) {
Run Code Online (Sandbox Code Playgroud)
小智 17
不是 PHPUnit 专家,但“each”函数在 PHP 8 中不再可用
警告:自 PHP 7.2.0 起,此函数已弃用,自 PHP 8.0.0 起已删除。强烈建议不要依赖此功能。
摘自PHP 网站
您使用的 PHPUnit 版本可能还不是 PHP 8 的最新版本。如果可以,请检查版本,然后在此处查看PHPUnit 版本支持