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?

Charles
  • 50,943
  • 13
  • 104
  • 142
Phillip B Oldham
  • 18,807
  • 20
  • 94
  • 134

4 Answers4

5

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

Jani Hartikainen
  • 42,745
  • 10
  • 68
  • 86
0

Use this at the previous line of error:

var_dump(debug_trace);
Cem Kalyoncu
  • 14,120
  • 4
  • 40
  • 62
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

Community
  • 1
  • 1
sakhunzai
  • 13,900
  • 23
  • 98
  • 159
-2

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

grantwparks
  • 1,124
  • 9
  • 13
  • 2
    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. – Sam Jan 31 '11 at 10:47