LoginSignup
0
0

More than 3 years have passed since last update.

PHPでは関数の引数が多くてもエラーにならない

Posted at

phpでは関数に引数を渡すときに定義されている数より多くてもエラーにはならないようです。

<?php

// 2つ引数で関数を呼び出す。
function twoArgumentFunction($one, $two)
{
    echo $one . ':' . $two;
}

# 引数二つで関数を呼び出す。
twoArgumentFunction('first', 'second'); 
// => first:second


// 3つの引数だと呼び出せる
twoArgumentFunction('first','second','third');
// => first:second

引数の数が少ないと「Fatal error」が発生します。

// 1つの引数で呼び出すとエラーになる
twoArgumentFunction('first');
// Fatal error: Uncaught ArgumentCountError: Too few arguments to function twoArgumentFunction(), 1 passed in index.php on line 13 and exactly 2 expected

0
0
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
0
0