• Resolved warnerta

    (@warnerta)


    Hi, I’m getting odd behavior with global array variables. After loading them with strings, they’re showing up with ordered numbers.

    I isolated the problem by making the code as simple as possible. I have this code in one function:

    `global $test_array;
    $test_array = array();

    $test_array[] = ‘test’;
    array_push ($test_array, ‘tester’);

    ?><p><?php
    echo ‘<pre>’;
    print_r($test_array);
    echo ‘</pre>’;
    ?></p><?php’`

    Which outputs, as expected:

    Array
    (
    [0] => test
    [1] => tester
    )

    For good measure I tested the array variable contents by inserting print code into another function that’s called later:

    `global $test_array;

    ?><p><?php
    echo ‘<pre>’;
    print_r($test_array);
    echo ‘</pre>’;
    ?></p><?php’`

    Which outputs, as expected:

    Array
    (
    [0] => test
    [1] => tester
    )

    There is no other code anywhere on my site that does anything to $test_array – nothing else even referencing that variable at all.

    Yet when I use Debug This – PHP – Variables, I see:

    test_array
    Array
    (
    [0] => 0
    [1] => 1
    )

    This same issue was happening with other array variables as well.

    Any idea what’s going on? Has anyone else seen anything like this? Is there some kind of universal global variable array stomper function hiding in WordPress?

    https://wordpress.org/plugins/debug-this/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter warnerta

    (@warnerta)

    Okay, I’ve tested this out enough that I’m certain this is a Debug This reporting error, which affects global array variables. The contents of the global array variables are correct and are not being stomped on. It’s Debug This’s reporting of the contents of global array variables’ contents that’s wrong.

    Plugin Contributor Chris Dillon

    (@cdillon27)

    Thanks for the details and troubleshooting. I’m not sure of the original intention but only array keys were being displayed, probably to avoid the deep nesting of globals like wp_filter.

    I changed it to report the actual value instead in version 0.4.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘global array variables report incorrectly or inexplicably stomped’ is closed to new replies.