Глава 35: контроль ошибок

This commit is contained in:
Igor Simdyanov
2022-05-25 21:00:08 +03:00
parent 2168ef90be
commit 0625de060e
7 changed files with 79 additions and 0 deletions

14
errors/trigger_error.php Normal file
View File

@ -0,0 +1,14 @@
<?php
function print_age(int $age)
{
$prefix = 'Функция print_age(): ';
$error = 'возраст не может быть отрицательным';
if ($age < 0) {
trigger_error($prefix . $error, E_USER_ERROR);
}
echo "Возраст составляет: $age";
}
// Вызов функции с отрицательным аргументом
print_age(-10);