<?php
$value=2;
if ($value>1){
error_log(“An error occured”,1,”info@phpcodez.com”,”From: from@phpcodez.com”);
}
?>
Tag Archives: Error
error_get_last
Example
<?php
echo “<pre>”;
echo $test;
print_r(error_get_last());
?>
Output
Array
(
[type] => 8
[message] => Undefined variable: test
[file] => /var/www/test/index.php
[line] => 3
)
debug_print_backtrace
It prints a backtrace
Example
<?php
echo “<pre>”;
function back($arg1, $arg2) {
debug_print_backtrace();
}
back(“test1”, “test2”);
?>
Output
#0 back(Peter, Griffin) called at [/var/www/test/index.php:6]
debug_backtrace
<?php
echo “<pre>”;
function back($arg1, $arg2) {
print_r(debug_backtrace());
}
back(“test1”, “test2”);
?>
The possible elements that can be returned are given below
function,line,file,class,object,type,Returns: “->” ,Returns: “::” ,Returns nothing,args
Output
Array
(
[0] => Array
(
[file] => /var/www/test/index.php
[line] => 6
[function] => back
[args] => Array
(
[0] => Peter
[1] => Griffin
)
)
)
Error functions
- debug_backtrace – It generate a generates a backtrace
- debug_print_backtrace – It prints a backtrace
- error_get_last – It returns the last error occurred
- error_log – It sends an error to the server error-log
- error_reporting – It specifies which errors are occurred.
- restore_error_handler – It restores the previous error handler
- restore_exception_handler – It r restores the previous exception handler
- set_error_handler – It sets a user-defined function to handle errors
- set_exception_handler – It sets a user-defined function to handle exception
- trigger_error – It can be used to create a custom error message .
- user_error – Its an alias of trigger_error()