Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP debug_backtrace bitmask usage

Trying to understand this entry in the php manual on debug_backtrace.

I don't understand what they mean by "this parameter is a bitmask for ...."

I have done web searches on bitmasks and my head is spinning round so I have decided I don't really want to learn the detail about it but just to know how I can supposed to add the options to that function.

Do I put in both options as in

debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, DEBUG_BACKTRACE_IGNORE_ARGS)

if I want both and one of them if I only want that one?

like image 314
Dayo Avatar asked Jun 30 '12 19:06

Dayo


People also ask

How do I get PHP to produce a Backtrace upon error?

For more advanced solution, you can use XDebug extension for PHP. By default when XDebug is loaded, it should show you automatically the backtrace in case of any fatal error. Or you trace into file (xdebug. auto_trace) to have a very big backtrace of the whole request or do the profiling (xdebug.

What is the Backtrace in PHP?

Definition and UsageThe debug_backtrace() function generates a PHP backtrace. This function displays data from the code that led up to the debug_backtrace() function. The current call type.

What is stack trace PHP?

So the stack trace is a list of the functions in the call stack at the point an exception is triggered. Throwing an exception is how the interpreter tells you an error has happened. This could be from a mistyped variable, incorrect input, or any type of exception that you've defined in your code.

How do you debug a backtrace?

To print a backtrace of the entire stack, use the backtrace command, or its alias bt . This command will print one line per frame for frames in the stack. By default, all stack frames are printed. You can stop the backtrace at any time by typing the system interrupt character, normally Ctrl-c .


1 Answers

Be aware that those 2 constants (DEBUG_BACKTRACE_PROVIDE_OBJECT, DEBUG_BACKTRACE_IGNORE_ARGS) are different in meaning. While DEBUG_BACKTRACE_PROVIDE_OBJECT provides an additional object when present, DEBUG_BACKTRACE_IGNORE_ARGS strips the args when present.

Since the most common use-case for these constants is to reduce memory usage, the way with least memory-consumption is:

debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

NOT

// false friend!
debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS);

It overrides the default of DEBUG_BACKTRACE_PROVIDE_OBJECT and additionally ignores DEBUG_BACKTRACE_IGNORE_ARGS.

like image 119
staabm Avatar answered Sep 22 '22 02:09

staabm