Take the State of PHP 2026 Survey →

Replace "Missing argument" warning with "Too few arguments" exception View as Markdown

Implemented (PHP 7.1)
Authors
Dmitry Stogov, dmitry@zend.com
Date
2016-06-01
Version
0.9
Source
wiki.php.net/rfc/too_few_args

Vote

Replace closed
Yes
39
No
11
50 voters
aharvey No 2016-06-14 22:24
ajf No 2016-06-12 20:43
bishop No 2016-06-06 14:23
bwoebi Yes 2016-06-06 11:23
cmb No 2016-06-06 13:39
colinodell Yes 2016-06-06 14:48
danack Yes 2016-06-16 00:04
daverandom Yes 2016-06-06 08:10
davey No 2016-06-09 20:13
derick No 2016-06-06 10:06
dm Yes 2016-06-07 20:31
dmitry Yes 2016-06-06 07:07
dragoonis Yes 2016-06-07 13:56
fa Yes 2016-06-06 09:46
galvao Yes 2016-06-08 00:11
guilhermeblanco Yes 2016-06-10 12:58
hywan Yes 2016-06-06 08:45
kalle Yes 2016-06-06 07:48
kguest No 2016-06-09 12:43
krakjoe Yes 2016-06-07 05:36
laruence Yes 2016-06-07 05:50
lcobucci Yes 2016-06-10 09:57
leigh Yes 2016-06-13 12:39
levim Yes 2016-06-10 16:36
lstrojny Yes 2016-06-07 07:15
marcio Yes 2016-06-06 14:28
mariano Yes 2016-06-06 14:22
mattwil Yes 2016-06-06 20:49
mcmic Yes 2016-06-07 04:38
mrook Yes 2016-06-09 21:09
nikic Yes 2016-06-06 09:59
ocramius Yes 2016-06-06 08:00
pajoye No 2016-06-16 03:05
patrickallaert No 2016-06-07 14:10
peehaa Yes 2016-06-11 21:24
pierrick Yes 2016-06-07 03:07
pmjones Yes 2016-06-07 02:47
pollita Yes 2016-06-07 00:14
rasmus Yes 2016-06-14 22:35
sammyk Yes 2016-06-07 16:32
santiagolizardo Yes 2016-06-06 15:46
sebastian No 2016-06-08 06:56
sobak Yes 2016-06-07 06:28
stas Yes 2016-06-06 17:03
thekid Yes 2016-06-06 20:24
tpunt Yes 2016-06-06 09:18
trowski Yes 2016-06-06 14:48
yohgaki Yes 2016-06-06 09:48
zeev Yes 2016-06-07 23:22
zimt No 2016-06-07 08:42

Discussions on the mailing list

Is the "No BC Breaks in Minor Releases" policy enforceable?
by Rowan Collins · 42 messages
Change to Too Few Args Exception RFC
by Davey Shafik · 8 messages
Change to Too Few Args Exception RFC
by Dmitry Stogov · 3 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:51 UTC

Introduction

Historically, PHP allows calling functions with fewer actual parameters than required by the function definition. These “non-passed” arguments lead to warning emission and continuation of function execution with uninitialized arguments.

function foo($a) {
   var_dump($a);   // NULL + Warning: Undefined variable: a 
   var_dump($a);   // NULL + Warning: Undefined variable: a
}
foo();             // Warning: Missing argument 1 for foo()

This strange behavior:

  • allows execution of functions with unexpected input data (nobody checks isset() for all arguments)
  • doesn't have real use cases (in any case, foo($a = null) is better)
  • may lead to warning bloating
  • disables obvious optimization opportunities

Proposal

I propose to disable calling “user” functions with insufficient actual parameters. PHP will throw an “Error” exception instead.

function foo($a) {
   var_dump($a);   // not executed
   var_dump($a);   // not executed
}
foo();             // throw Error("Too few arguments to function foo(), 0 passed in %s on line %d and exactly 1 expected")

Using this approach, all attempts to call functions with unexpected input data are going to be caught as soon as possible.

Behavior of internal functions is not going to be changed.

Backward Incompatible Changes

The BC break in intended.

Proposed PHP Version(s)

PHP 7.1

Proposed Voting Choices

The vote is a straight Yes/No vote, that requires a 2/3 majority. The voting began on Jun 6 and will close on Jun 16.

Vote: Replace — Yes: 39 · No: 11 (closed)

Patches and Tests

PR 1928

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit ff363e2e7c58353b7e2751d1ca4d7bf616862aae
  3. a link to the PHP manual entry for the feature