Skip to content

"Global" variables not accessible #2200

@phh

Description

@phh

See https://wordpress.org/support/topic/a2a_share_save_plugin_dir-not-set-and-breaks-wp-cli?replies=6

I'm getting some errors from wp-cli, due to the add-to-any plugin is defining their variables in the global scope.

See answer from micropat:
https://wordpress.org/support/topic/a2a_share_save_plugin_dir-not-set-and-breaks-wp-cli?replies=6#post-7650210

This is a WP-CLI issue, not an AddToAny issue.

Using a reduced test case, WP-CLI 0.21.0 fails, but WP-CLI 0.20.2 worked.

// Already global scope, so the global keyword isn't used.
//global $a_global_var;

$a_global_var = 'Of course.';

function foo() {
    global $a_global_var;

    if ( empty( $a_global_var ) ) {
        $a_global_var = 'Nope!';
    }

    die( 'Is global scope behaving? ' . $a_global_var . " \n" );
}

foo();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions