php[world] 2018 - Call for Speakers

ArgumentCountError

(PHP 7 >= PHP 7.1.0)

Introduction

ArgumentCountError is thrown when too few arguments are passed to a user-defined function or method.

Class synopsis

ArgumentCountError extends TypeError {
/* Inherited methods */
final public string Error::getMessage ( void )
final public Throwable Error::getPrevious ( void )
final public mixed Error::getCode ( void )
final public string Error::getFile ( void )
final public int Error::getLine ( void )
final public array Error::getTrace ( void )
final public string Error::getTraceAsString ( void )
public string Error::__toString ( void )
final private void Error::__clone ( void )
}
add a note add a note

User Contributed Notes 2 notes

up
1
T7To7
2 months ago
Note if an invalid number of arguments are passed to a built-in function an ArgumentCountError exception will be thrown if and only if your code is in strict mode.

<?php
declare(strict_types = 1);

try {
    echo
strlen('ahmed', 4);
} catch (
ArgumentCountError $e) {
    echo
$e->getMessage()';
}
?>
up
0
lincoln dot du dot j at gmail dot com
10 months ago
<?php

function dosomething($a,$b){
    return
$a/$b;
}

try{
   
dosomething(1);
}catch(
Exception $e){
    echo
$e;
}catch(
ArgumentCountError $er){
    echo
$er->getMessage();
}catch(
DivisionByZeroError $d){
    echo
$d;
}
?>
//Output
Too few arguments to function dosomething(), 1 passed in [...][...] on line 10 and exactly 2 expected
To Top