i have this:
i have An HTTACCESS file with directive to prepend a file for config and handle error: (it is mandatory: According to the documentation, this file must be attached before any other php script is executed in order to obtain errors: such as E_PARSE.)
php_value auto_prepend_file "./server/conferror.php"
the content of conferror.php:
<?php declare(strict_types=1); ini_set('session.gc_maxlifetime', '0'); ini_set('session.use_only_cookies', '1'); ini_set('session.cookie_httponly', '1'); ini_set('allow_url_fopen', '1'); ini_set('allow_url_include', '1'); ini_set('error_reporting', '1'); ini_set('display_errors', '0'); error_reporting(E_ALL); set_error_handler("ErrorHandler"); register_shutdown_function("ShutdownHandler"); function ErrorHandler($error_level, $error_message, $error_file, $error_line, $error_context) { $ErrorHandler = "<b>File:</b> " . $error_file . '<br>' . "<b>Line :</b> " . $error_line . '<br>' . "<b>Desc:</b> <br>" . $error_message . '<br>'; echo $ErrorHandler; exit; } function ShutdownHandler() { $CheckError = error_get_last(); if ($CheckError != null) { $ErrorHandler = "<b>File:</b> " . $CheckError['file'] . '<br>' . "<b>Line :</b> " . $CheckError['line'] . '<br>' . "<b>Desc:</b> <br>" . $CheckError['message'] . '<br>'; echo $ErrorHandler; exit; } } ?>
in my index.php i have this to start work the aplication:
<?php require_once 'class.Main.php'; $WebAPP = new CORE(); $WebAPP->Main(); ?>
in Main file i have a test, this code to unset a Static Object and Test Erros Handlers:
<?php class CORE { public static $ObjClass; public function __construct() { self::$ObjClass['data']='data'; } public function __destruct() { unset(CORE::$ObjClass); } public function Main() { #not Test on this. } } ?>
I have 3 questions:
- Why Event handler does not capture the following error?
Fatal error: Uncaught Error: Attempt to unset static property CORE::$ObjClass in C:xampphtdocsdev2class.Main.php:8 Stack trace: #0 [internal function]: CORE->__destruct() #1 {main} thrown in C:xampphtdocsdev2class.Main.php on line 8
Second test:
This code:
<?php
class CORE {
public function __construct() {
}
public function __destruct() {
prom();
}
public function Main() {
#not Test on this.
}
}
?>
Generate this error:
Fatal error: Uncaught Error: Call to undefined function prom() in C:xampphtdocsdev2class.Main.php:6 Stack trace: #0 [internal function]: CORE->__destruct() #1 {main} thrown in C:xampphtdocsdev2class.Main.php on line 6
Update:
after much test i see that the error handler work fine with errors in declared function; but this not work in __construct
or__destruct
function.