4

I'm getting a fatal "Call to a member function on a non-object" error in a PHP script, but I'm unable to track down exactly where this is happening, or why. The error message is pretty-much useless, as the line it describes works 99.9% of the time.

Is there a way I can get the current call stack, trace what calls are being made before this fatal error, or do anything else to help track down this bug?

4 Answers 4

5

I would recommend installing Xdebug on your development server. It's a very valuable tool in cases like these.

Sign up to request clarification or add additional context in comments.

Comments

0

Use this at the previous line of error:

var_dump(debug_trace); 

1 Comment

you can use <pre> tags to improve your output.
0

please see my answer and others also for various possibilities

How do I catch a PHP Fatal Error

Obviously this is partially related in a sense it catches only fatal error . You can modify the function to catch other type of errors . The starting point for this is :

if($error['type'] == 1){ 

This methods overrides Xdebug output if setup already .

regards sakhunzai

Comments

-2

Use debug_print_backtrace() - https://www.php.net/manual/en/function.debug-print-backtrace.php

1 Comment

This doesn't seem to work for fatal errors. You can register a shutdown function which runs when the fatal error appears, but at this point the callstack is already cleared and the only thing you'll se in the callstack is your own shutdown handler.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.