CKTIS / PHP
ArgumentCountError
ArgumentCountError deriva de TypeError.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
try { strlen("a", "b"); } catch (ArgumentCountError $e) { /* ... */ }ArgumentCountError deriva de TypeError. Em PHP 8.4 ocorre por falta de um argumento obrigatório de uma função do utilizador ou excesso de argumentos posicionais numa função interna não variádica. Uma função do utilizador pode ler argumentos posicionais adicionais com func_get_args. Sem o argumento exigido o corpo de first não é executado.
function first($value) { return count(func_get_args()); }
foreach ([fn() => first(), fn() => strlen("x", "y")] as $call) {
try { $call(); } catch (ArgumentCountError $e) {
echo get_class($e), " ", ($e instanceof TypeError ? "TypeError" : "other"), PHP_EOL;
}
}
echo first("A", "B");
ArgumentCountError TypeError
ArgumentCountError TypeError
2
Exemplos
<?php
function first($value) { return count(func_get_args()); }
foreach ([fn() => first(), fn() => strlen("x", "y")] as $call) {
try { $call(); } catch (ArgumentCountError $e) {
echo get_class($e), " ", ($e instanceof TypeError ? "TypeError" : "other"), PHP_EOL;
}
}
echo first("A", "B");
Resultado
ArgumentCountError TypeError ArgumentCountError TypeError 2