Store a value in global scope after init hook is fired

So after consulting on Facebook Advanced WordPress group, the advice was to create an object with setters and getters instead of using the declaring and getting variables in the global scope as shown in the code below:

class MyPlugin
{
  public $current_post_types;

  public function __construct()
  {
    add_filter('init', array($this, 'get_variables'));
  }


  public function get_variables()
  {
    $this->current_post_types = get_post_types(array(
      'public' => true,
      'show_in_rest'   => true,
    ), 'objects');
  }
}

$skeleton = new MyPlugin();

function mk_post_types()
{
  global $skeleton;
  $current_post_types = $skeleton->current_post_types;
  //remaining code below
}

This solved the issue, now I can get all custom post types in the mk_post_types function.