Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] handler funkcji w klasie
flashdev
post
Post #1





Grupa: Zarejestrowani
Postów: 812
Pomógł: 117
Dołączył: 2.12.2008

Ostrzeżenie: (10%)
X----


Piszęe klasę do obsługi błędów w php i mam mały problem.

Kod
function error_handler(..){
...
}
set_error_handler(error_handler);


ten kod mi działa, ale jak chce podać uchwyt do funkcji w klasie to jest problem

Kod
// tak nie dziala:
set_error_handler($this->error_handler);
// tak tez nie:
set_error_handler("$this->error_handler");


Jestem przyzwyczajony do JS i tam normalnie nazwa funkcji bez nawiasów jest do niej uchwytem.
A w php np. ponizsze wyrazenie jest prawdziwe:
Kod
echo gettype(abc)==gettype("abc");


Czyli pomimo ze mam w kodzie funkcje abc, to php traktuje to jako string, a nie uchwyt.

Jak rozwiazac ten problem, jak odwolac sie do tej funkcji w klasie?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Cytat(erix @ 3.07.2009, 20:10:40 ) *
  1. <?php
  2. set_error_handler(array(&$this, 'catchPhpError'));
  3. ?>


Raczej w czasach php4 (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Panie Erixie (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

~Flashdev pamietaj ze error handler dotyczy tylko części błędow.

Cytat
The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.


Poza tym masz błędy typu 'Undefined variable $err_no', wiec musisz użyc ' zamiast ", reszta jest ok. Pomijając, że źle wyświetlasz niektóre zmienne.

  1. <?php
  2. class class_error_reporting {
  3.  
  4.    function __construct(){
  5.        //set_error_handler(array($error_rep, 'error_handler'));
  6.        set_error_handler(array($this, 'error_handler'));
  7.    }
  8.  
  9.    function error_handler($errno, $errstr, $errfile, $errline, $errcontext){
  10.        echo '$err_no = '.$errno.'\n';
  11.        echo '$err_str = '.$errstr.'\n';
  12.        echo '$err_file = '.$errfile.'\n';
  13.        echo '$err_line = '.$errline.'\n';
  14.        echo '$err_context = '.$errcontext.'\n';
  15.        echo '------------------------------'.'\n';
  16.    }
  17. }
  18.  
  19. new class_error_reporting();
  20.  
  21.  
  22. trigger_error('heheh', E_USER_NOTICE);
  23. ?>


Ten post edytował wookieb 3.07.2009, 20:52:40
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 13.10.2025 - 16:44