Shortcode Inside Class Not Working

if you use any hooks, filters or shortcodes with class methods, you have three options.

either declare it in the context of an instance, in which case, you can refer to the instance of the class.

class myClass {
    function __construct()
    {
        add_shortcode('my_shortcode_name', [ $this, 'shortcode' ]);
    }
    
    function shortcode()
    {
        //your code here
        //properties of the instance are available
        return 'a string';
    }
}

or you declare it outside of an instance, then you must use a public static method.

add_shortcode('my_shortcode_name', [myClass::class, 'shortcode']);

class myClass {
    
    
    public static function shortcode()
    {
        //your code here
        //you only have access to static properties
        return 'a string';
    }
    
}