Skip to content

debug_backtrace() was changed in PHP 7 #1238

@bigin

Description

@bigin

Strange behavior of debug_backtrace() detected, seems that it was changed in PHP 7 >, so that add_action() will not work in the same way. The counter $shift is now one level less. An example to reproduce it:

<?php

register_plugin(
    'add_action_test',
    'add_action_test',
    '0.1',
    'J. Ehret',
    'http://ehret-studio.com',
    'Testing strange behavior of add_action()',
    '',
    ''
);

add_action('index-post-dataindex', 'add_action_test');

function add_action_test() {
    include __DIR__.'/A.php';
    $a = new A;
    $a->fireFoo();
}

A.php looks as follows:

<?php

class A {
    function fireFoo() {
        add_action('theme-header', function() { echo 'here in foo() ...'; });
    }
}

Adding version_compare() into add_action() could solve that issue:

...
$shift=count($bt) - 4;
if(version_compare(PHP_VERSION, '7.0.0', '>=')) {
    $shift--;
}
...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions