Get variable value based on string constant

You can do that, but you shouldn’t:

  1. Keep the global namespace clean. Each name in the global namespace is a collision candidate. Making a variable global, a constant or a function increases the likelihood of a collision, no matter how good your prefixes are.

  2. Constants are the slowest global types. Yes, that’s micro-optimization, but why introducing it when there are better options?

  3. Constants are not flexible. Imagine you change your shortcode callback to accept two parameters. Or five. Or ten. Your code will become very ugly very fast.

Alternatives

Provide the defaults in a separate function:

function my_plugin_prefix_get_default_shortcode_attributes()
{
    return array (
        'numitems' => 5
    );
}

Now you can access these defaults from any place, and you can extend the array easily.

In your shortcode:

$attribute = shortcode_atts( 
    my_plugin_prefix_get_default_shortcode_attributes(),
    $atts
);

Move the function into your plugin’s main class or into a separate class:

class My_Plugin
{
    public static function get_default_shortcode_attributes()
    {
        return array (
            'numitems' => 5
        );
    }
}

In your shortcode:

$attribute = shortcode_atts( 
    My_Plugin::function get_default_shortcode_attributes(),
    $atts
);