fork download
  1. <?php
  2. class MyClass {
  3. private $ErrorHandler = null;
  4.  
  5.  
  6. // Зарегистрировать обработчик ошибок
  7. public function RegisterErrorHandler($ErrorHandlerFn) {
  8. $this->ErrorHandler = $ErrorHandlerFn;
  9. }
  10.  
  11.  
  12. // Симуляция ошибки
  13. public function TestError(){
  14. if(is_callable($this->ErrorHandler)) { // Если определен обработчик ошибок
  15. call_user_func($this->ErrorHandler,'Текст ошибки');
  16. }
  17. }
  18.  
  19. }
  20.  
  21.  
  22. $myClass = new MyClass();
  23.  
  24. $myClass->RegisterErrorHandler(function($errorText){
  25. echo $errorText;
  26. });
  27.  
  28. $myClass->TestError();
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Текст ошибки