中級 › ArgumentCountError: Too few arguments passed の原因と直し方 › パターン3
ArgumentCountError: Too few arguments passed の原因と直し方
関数が必要とする数より少ない引数しか渡さなかったときに出るエラーです。
1 <?php 2 function makeUser(string $name, int $age) { 3 return "$name is $age"; 4 } 5 echo makeUser("Al"______); ^
Fatal error: Uncaught ArgumentCountError: Too few arguments to function makeUser(), 1 passed in main.php on line 5 and exactly 2 expected in main.php:2
空欄を埋めて実行を通す
$ageにはデフォルト値が無いため省略できません。省略するとArgumentCountErrorになります。
次の問題