4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPUnitをしていたらMaximum function nesting level of 'xxx' reached, aborting!となったときの対応方法

Posted at

事象 : トレイトを使ってテストをしていたら怒られた

Testing started at 10:12 ...
path\to\xampp\php\php.exe path/to/vendor/phpunit/phpunit/phpunit --no-configuration ...
PHPUnit 6.5.8 by Sebastian Bergmann and contributors.

PHP Fatal error:  Maximum function nesting level of '256' reached, aborting! in path\to\vendor\laravel\framework\src\Illuminate\Support\helpers.php on line 1106
PHP Stack trace:
PHP   1. {main}() path\to\vendor\phpunit\phpunit\phpunit:0
//..省略..
PHP 256. trait_uses_recursive($trait = *uninitialized*) path\to\vendor\laravel\framework\src\Illuminate\Support\helpers.php:1109

原因 : 実行したループが多すぎるから

注意: 100 から 200 を超えるようなレベルの再帰呼び出しは避けてください。そんなことをすると、 スタックが破壊され、スクリプトが異常終了してしまいます。 無限に続くような再帰処理は、プログラミングの間違いでしょう。
PHP: ユーザー定義関数 - Manual

一時的対策 : XDebugの設定でループカウントを上げる

PHP - Fatal error: Maximum function nesting level of '100' reached, aborting!|teratail

php.ini
[XDebug]
;他の設定は省略
xdebug.max_nesting_level=300
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?