title: Variable in global variable: "global variable{variable}". It works, but is it OK?
body: <p><strong>TL;DR:</strong> Say I have a global instantiated class </p>
  
  <pre><code>$GLOBALS['my_plugin'] = instance(); 
  </code></pre>
  
  <p>and I want to use it somewhere else, but I dont know the name 'my_plugin'. Actually I do of course, but my helper files don't. In order to So I use;</p>
  
  <pre><code>$plugin_name = 'my_plugin';
  global $plugin_name, ${$plugin_name};
  </code></pre>
  
  <p>And it works I can access $my_plugin variable and use the object just fine. What I am doing is basically making use of "variable variables",but it somehow feels weird. Is it OK ? Or is there a better way to tackle this.</p>
  
  <p><strong>Long Version</strong></p>
  
  <pre><code>// contents of plugin.php
  class myplugin_class {
      $_instance = null;
      public $plugin_name = 'my_plugin';
  
      public function __construct() {
          $this-&gt;init();
      }
      public static function instance() {
          if ( is_null( self::$_instance ) ) {
              self::$_instance = new self();
          }
          return self::$_instance;
      }
      function init() {
         $this-&gt;assign_global();
         $this-&gt;include_helper();
      }
      function assign_global() {
          global $plugin_slug;
          $plugin_slug = $this-&gt;plugin_name;
      }
      function include_helper() {
          include_once('helper.php' );
      }
  
  
  }//end class
  function plug_inst() {
      return myplugin_class::instance();
  }
  
  $GLOBALS['my_plugin'] = plug_inst();
  </code></pre>
  
  <p>Helper.php</p>
  
  <pre><code>// contents of helper.php
  class helper_class {
      public function __construct() {
          $this-&gt;some_function_that_needs_my_plugin_object();
      }
      function some_function_that_needs_my_plugin_object() {
          global $plugin_slug, ${$plugin_slug};
          print_r(${$plugin_slug});
          //It gives me the $my_plugin object I want. It's all good, it works. But is it OK?
      }
  }
  </code></pre>