The Error
You called a function and left out one or more required arguments. PHP stops execution immediately and throws:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function update_user(), 1 passed and exactly 2 expected
Execution dies on the spot. PHP 7+ promoted this from a silent warning into a real ArgumentCountError โ so PHP 5 code that quietly "worked" will now crash hard.
Root Cause
Your call site isn't giving the function everything its signature demands. Two causes cover most cases: the function grew a new required parameter after a merge or update, or the call was always incomplete and PHP 5 simply never complained.
Example that triggers this:
<?php
function update_user(int $user_id, string $name): bool {
// updates user in DB
return true;
}
// Wrong โ only passing 1 argument
update_user(42);
// Fatal error: Too few arguments to function update_user(), 1 passed and exactly 2 expected
Fix 1: Pass the Missing Argument
Check what the function signature actually expects, then pass everything it needs:
<?php
// Correct โ pass both required arguments
update_user(42, 'John Doe');
Not sure what parameters a function takes? Reflection prints every param and whether it's optional:
<?php
$ref = new ReflectionFunction('update_user');
foreach ($ref->getParameters() as $param) {
echo '$' . $param->getName();
if ($param->isOptional()) {
echo ' (optional, default: ' . var_export($param->getDefaultValue(), true) . ')';
} else {
echo ' (required)';
}
echo "\n";
}
Fix 2: Make the Parameter Optional
When the missing argument has a sensible default, declare it in the function signature โ callers won't need to pass it:
<?php
function update_user(int $user_id, string $name = ''): bool {
if ($name === '') {
// fetch from DB or skip name update
}
return true;
}
// Now both of these work
update_user(42); // uses default empty string
update_user(42, 'John'); // uses provided name
Only reach for this when an empty or null default genuinely makes sense. Don't use it to paper over missing data.
Fix 3: Use Variadic Syntax for a Variable Number of Arguments
When a function legitimately handles any number of extra arguments, variadic syntax is the right tool:
<?php
function update_user(int $user_id, string ...$fields): bool {
foreach ($fields as $field) {
// handle each field
}
return true;
}
update_user(42); // zero extra args โ fine
update_user(42, 'name'); // one extra arg
update_user(42, 'name', 'email'); // two extra args
Fix 4: Check for Method Calls on Objects
Class methods throw the same error. Find the class and method name in the stack trace, then apply the same fix:
<?php
class UserService {
public function update(int $user_id, array $data): bool {
return true;
}
}
$service = new UserService();
// Wrong
$service->update(42);
// Fatal error: Too few arguments to function UserService::update(), 1 passed and exactly 2 expected
// Correct
$service->update(42, ['name' => 'John']);
Tracking Down the Call Site
The error names the function but often skips where it was called from. Wire up an exception handler to surface the full trace:
<?php
// At the top of your entry file (dev only)
set_exception_handler(function (Throwable $e) {
echo $e->getMessage() . "\n";
echo $e->getTraceAsString();
});
Or tail the error log directly:
tail -f /var/log/php/error.log
# or for PHP-FPM:
tail -f /var/log/php8.2-fpm.log
Either way, you get the exact file and line of the bad call:
#0 /var/www/html/controllers/UserController.php(45): update_user(42)
#1 /var/www/html/index.php(12): UserController->save()
PHP 7 vs PHP 8 Behavior
PHP's handling of this error tightened considerably across versions โ worth knowing if you're upgrading old code:
- PHP 5.x: Missing arguments triggered an
E_WARNING. Execution continued with the missing param silently set tonull. - PHP 7.0+: Throws
ArgumentCountError(extendsTypeError). Fatal if uncaught. - PHP 8.x: Same behavior as 7, but now internal PHP functions also throw
ArgumentCountErrorfor missing args.
Migrating a PHP 5 codebase to 7+? Expect this error to surface calls that have been quietly broken for years.
Verification
Run a quick sanity check once you've made the change:
# Run the script from CLI
php -f your_script.php
# Or lint it first
php -l your_script.php
On Laravel or Symfony, hit the exact route or artisan command that originally crashed. No fatal errors in the log means you're done.
Prevention
- Strict types: Add
declare(strict_types=1);at the top of your files. It won't stop argument count errors directly, but type discipline catches mismatches early. - Static analysis: PHPStan or Psalm flags argument count mismatches before your code ever runs:
vendor/bin/phpstan analyse src/ --level=5 - Unit tests: A test that calls the function with the right arguments breaks immediately if someone changes the signature.
- PHPDoc: Document required vs optional params with
@paramblocks โ your IDE will flag bad calls as you type.

