Answers.Body: <p>Boom!</p>
  
  <p>So I just needed to put an underscore between the plugin handle and variable name so <code>PluginAnotherVariable.php</code> becomes <code>Plugin_AnotherVariable.php</code> and the classname <code>Plugin_AnotherVariable</code> and things are now working :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-13T18:14:25.800Z
Answers.LastActivityDate: 2016-02-13T18:14:25.800Z
Answers.UserDisplayName: Alec Ritson
Body: <p>I have a plugin with the structure something like:</p>
  
  <pre><code>variables
   - PluginVariable.php
   - PluginAnotherVariable.php
  </code></pre>
  
  <p>Inside <code>PluginVariable.php</code> I have something like:</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  class PluginVariable
  {
     public function foo($parameter)
     {
         $result = craft()-&gt;plugin_results-&gt;get($parameter);
          return new PluginAnotherVariable($result);
     }
  }
  </code></pre>
  
  <p>Now when I do <code>{{ craft.plugin.foo('something') }}</code> I just get <code>Fatal error: Class 'Craft\PluginAnotherVariable' not found</code>.</p>
  
  <p>I've checked that the filenames and classnames are identical and the namespacing etc so the class most certainly exists but I can't get this to work, has anyone had a similar issue with this and what could be causing it? Thanks.</p>
  
Tags: <plugin-development><plugins>
Title: How do you return an instance of a variable class from within a different variable class?
ThreadText: # How do you return an instance of a variable class from within a different variable class?
  
  (Asked by: username_0 on 2016-02-13)
  
  I have a plugin with the structure something like:
  
  ```
  variables
   - PluginVariable.php
   - PluginAnotherVariable.php
  
  ```
  
  Inside `PluginVariable.php` I have something like:
  
  ```
  <?php
  namespace Craft;
  
  class PluginVariable
  {
     public function foo($parameter)
     {
         $result = craft()->plugin_results->get($parameter);
          return new PluginAnotherVariable($result);
     }
  }
  
  ```
  
  Now when I do `{{ craft.plugin.foo('something') }}` I just get `Fatal error: Class 'Craft\PluginAnotherVariable' not found`.
  
  I've checked that the filenames and classnames are identical and the namespacing etc so the class most certainly exists but I can't get this to work, has anyone had a similar issue with this and what could be causing it? Thanks.
  
  **Tags:** plugin-development, plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-02-13. Score: 3 | Accepted answer
  
  Boom!
  
  So I just needed to put an underscore between the plugin handle and variable name so `PluginAnotherVariable.php` becomes `Plugin_AnotherVariable.php` and the classname `Plugin_AnotherVariable` and things are now working :)
  
  
  ---
  
  