Help us understand the problem. What is going on with this article?

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

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした