Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

phpunit

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)

like image 300
Juliano Avatar asked Dec 10 '25 12:12

Juliano


2 Answers

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 ($args as $i => $arg) {
like image 51
Simon Avatar answered Dec 13 '25 04:12

Simon


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

like image 44
Pit Avatar answered Dec 13 '25 04:12

Pit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!