Sangoku
Sangoku

Reputation: 1606

Get error line number and file name from which the class call was made

I have a class for handling errors.

I would like to call a public static method of the class to log the errors my RPC server is throwing at me without the need to use the __LINE__ comand.

Something like this:

class errorHander{
    public static $errors = array();
    public static function logError($message){
        self::$errors[] = array('message', NEEED SOMHOW TO GET THE calling class, get the file in which the error ocured);
    }
}

And this is most important, without passing the file location from the called function.

So something like errorHander:logError(message, location) is a no go.

Upvotes: 0

Views: 4046

Answers (4)

Jojo
Jojo

Reputation: 2760

This is possible with the xdebug-extension: http://xdebug.org

You may use xdebug_call_file() and xdebug_call_class() to get the information you need.

See the documentation: http://xdebug.org/docs/all_functions

Upvotes: 0

Nwafor
Nwafor

Reputation: 184

logError() need only one parameter not 2.

do something like this:

 class errorHander{
        public static $errors = array();
        public static function logError($message){
            self::$errors[] = array('message'=>$message);
        }
    }


    errorHander:logError("This is a no-yes go") //This should log

    echo errorHander:errors[0]["message"]; //print it

hope it helps

Upvotes: 0

geekman
geekman

Reputation: 2244

Exception::getLine and getFile methods, I donot way a way to do this without handling Exceptions. Heres a reference. http://www.php.net/manual/en/class.exception.php

Upvotes: 1

arkascha
arkascha

Reputation: 42925

Well this obviously depends on what kind of error you have.

You might want to look at exception handling. PHPs exception class offers the methods getLine() and getTrace(). This might be what you are looking for.

Upvotes: 0

Related Questions