'(PHPUnit) PHP Fatal error: Uncaught Error: Call to undefined function each()

firstly I was receiving a warning and a fatal error. The warning:

Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?

Then I replaced the continue with break and the warning disappeared. But even after the replacement, the fatal error still happens. The fatal error:

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()

The line 77-83 of Getopt.php

        reset($args);
        array_map('trim', $args);

        while (list($i, $arg) = each($args)) {
            if ($arg == '') {
                continue;
            }

Im using PHP 8.0.1 and the PHPUnit 9 (at least I think, because I cant use commands to check, and I downloaded it after february 7)



Solution 1:[1]

not an expert of PHPUnit but the "each" function is not available anymore in PHP 8

Warning: This function has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged.

Taken from the PHP site

Probably the PHPUnit version you're using is not up-to-date yet for PHP 8. Check the version if you can and then see here PHPUnit version support

Solution 2:[2]

Probably the PHPUnit version you're using is not up-to-date yet for PHP 8 try

while (list($i, $arg) = each($args)) {

into

foreach ($arg as $arg,) {

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 Simon