search

Home  >  Q&A  >  body text

"(PHPUnit) PHP fatal error: Uncaught error: Call to undefined function each()"

<p>First, I got a warning and a fatal error. Warning: </p> <pre class="brush:php;toolbar:false;">Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?</pre> <p>Then I replaced continue with break and the warning disappeared. But even after replacing, the fatal error still occurs. Fatal error: </p> <pre class="brush:php;toolbar:false;">PHP Fatal error: Undefined function each() was called at line 80 of D:xamppphppearPHPUnitUtilGetopt.php Stack trace: #0 D:xamppphppearPHPUnitTextUICommand.php(242): PHPUnit_Util_Getopt::getopt(Array, 'd:c:hv', Array) #1 D:xamppphppearPHPUnitTextUICommand.php(138): PHPUnit_TextUI_Command->handleArguments(Array) #2 D:xamppphppearPHPUnitTextUICommand.php(129): PHPUnit_TextUI_Command->run(Array, true) #3 D:xamppphpphpunit(46): PHPUnit_TextUI_Command::main() #4 {main} Throws at line 80 of D:xamppphppearPHPUnitUtilGetopt.php Fatal error: Undefined function each() called in D:xamppphppearPHPUnitUtilGetopt.php on line 80 Stack trace: #0 D:xamppphppearPHPUnitTextUICommand.php(242): PHPUnit_Util_Getopt::getopt(Array, 'd:c:hv', Array) #1 D:xamppphppearPHPUnitTextUICommand.php(138): PHPUnit_TextUI_Command->handleArguments(Array) #2 D:xamppphppearPHPUnitTextUICommand.php(129): PHPUnit_TextUI_Command->run(Array, true) #3 D:xamppphpphpunit(46): PHPUnit_TextUI_Command::main()</pre> <p>Lines 77-83 of Getopt.php</p> <pre class="brush:php;toolbar:false;">reset($args); array_map('trim', $args); while (list($i, $arg) = each($args)) { if ($arg == '') { continue; }</pre> <p>I'm using PHP 8.0.1 and PHPUnit 9 (at least I think so since I can't check with the command and I downloaded it after February 7th) </p>
P粉877114798P粉877114798461 days ago520

reply all(1)I'll reply

  • P粉378890106

    P粉3788901062023-08-24 00:30:19

    I'm no expert on PHPUnit, but the "each" function is no longer supported in PHP 8

    Quoted from PHP official website

    Maybe the PHPUnit version you are using is not adapted to PHP 8. If possible, please check the version and then refer to PHPUnit version support

    reply
    0
  • Cancelreply