: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
private $debug_backtrace = [];
private $debug_backtrace_function;
* DebugBackTrace constructor.
* @param bool $provide_object
* @param bool $ignore_args
* @param null $debug_backtrace_function
public function __construct(
$debug_backtrace_function = null
if ( ! $debug_backtrace_function ) {
$debug_backtrace_function = 'debug_backtrace';
$this->provide_object = $provide_object;
$this->ignore_args = $ignore_args;
$this->debug_backtrace_function = $debug_backtrace_function;
* @param array $functions
public function are_functions_in_call_stack( array $functions, $refresh = true ) {
if ( empty( $this->debug_backtrace ) || $refresh ) {
foreach ( $this->debug_backtrace as $frame ) {
if ( isset( $frame['class'] ) ) {
$frame_function = [ $frame['class'], $frame['function'] ];
$frame_function = $frame['function'];
if ( in_array( $frame_function, $functions, true ) ) {
* @param string $function_name
public function is_function_in_call_stack( $function_name, $refresh = true ) {
return $this->are_functions_in_call_stack( [ $function_name ], $refresh );
* @param string $function_name
public function count_function_in_call_stack( $function_name, $refresh = true ) {
if ( empty( $this->debug_backtrace ) || $refresh ) {
foreach ( $this->debug_backtrace as $frame ) {
if ( ! isset( $frame['class'] ) && $frame['function'] === $function_name ) {
* @param string $class_name
* @param string $function_name
public function is_class_function_in_call_stack( $class_name, $function_name, $refresh = true ) {
return $this->are_functions_in_call_stack( [ [ $class_name, $function_name ] ], $refresh );
public function get_backtrace() {
// As of 5.3.6, 'options' parameter is a bit mask for the following options.
if ( $this->provide_object ) {
$options |= DEBUG_BACKTRACE_PROVIDE_OBJECT;
if ( $this->ignore_args ) {
$options |= DEBUG_BACKTRACE_IGNORE_ARGS;
$actual_limit = 0 === $this->limit ? 0 : $this->limit + 4;
$this->debug_backtrace = (array) call_user_func_array(
$this->debug_backtrace_function,
); // Add one item to include the current frame.
$this->remove_frames_for_this_class();
return $this->debug_backtrace;
private function remove_frames_for_this_class() {
* We cannot rely on number of frames to remove.
* php 5.6 and 7+ provides different call stacks.
* php 5.6 adds call_user_func_array from get_backtrace()
if ( ! isset( $this->debug_backtrace[0] ) ) {
$frame = $this->debug_backtrace[0];
( isset( $frame['file'] ) && __FILE__ === $frame['file'] )
|| ( isset( $frame['class'] ) && self::class === $frame['class'] )
$this->remove_last_frame();
$this->remove_last_frame(); // Remove frame with the function called this class.
public function remove_last_frame() {
if ( $this->debug_backtrace ) {
array_shift( $this->debug_backtrace );