Fungsi trigger_error
Fungsi trigger_error menjana mesej ralat pengguna. Parameter pertamanya menerima teks mesej, dan yang kedua - tahap ralat (lalai E_USER_NOTICE). Fungsi ini berguna untuk penyahpepijat dan mencipta sistem pengendalian ralat sendiri.
Sintaks
trigger_error(message, error_level);
Contoh
Jana notis mudah:
<?php
trigger_error("This is a notice message");
?>
Hasil pelaksanaan kod:
Notice: This is a notice message in file.php on line 2
Contoh
Jana amaran pengguna:
<?php
trigger_error("Invalid value entered", E_USER_WARNING);
?>
Hasil pelaksanaan kod:
Warning: Invalid value entered in file.php on line 2
Contoh
Jana ralat maut:
<?php
trigger_error("Critical system error", E_USER_ERROR);
?>
Hasil pelaksanaan kod:
Fatal error: Critical system error in file.php on line 2
Contoh
Penggunaan dalam struktur bersyarat:
<?php
$age = -5;
if ($age < 0) {
trigger_error("Age cannot be negative", E_USER_WARNING);
}
?>
Hasil pelaksanaan kod:
Warning: Age cannot be negative in file.php on line 4