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
flashdev
post
Post #2





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

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


Można prosić o mały feedback co robie źle?

Kod
<?php
include("class_error_reporting.php");
$error_rep = new class_error_reporting();

//asd
?>


Kod
<?php

class class_error_reporting {

    function __construct(){
        //set_error_handler(array($error_rep, 'error_handler'));
        set_error_handler(array($this, 'error_handler'));
    }

    function error_handler($errno, $errstr, $errfile, $errline, $errcontext){
        echo "$err_no = ".$errno."\n";
        echo "$err_str = ".$errstr."\n";
        echo "$err_file = ".$errfile."\n";
        echo "$err_line = ".$errline."\n";
        echo "$err_context = ".$errcontext."\n";
        echo "------------------------------"."\n";
    }
}

?>


Ten post edytował flashdev 3.07.2009, 17:41:12
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: 24.12.2025 - 15:07