Answers.Body: <p>You can simply load the file normally via php <a href="http://php.net/manual/en/function.require-once.php" rel="nofollow noreferrer">require once </a></p>
  
  <pre><code>require_once( __DIR__ . '/resources/DateFormatting.php');
  $dataFormatter = new DateFormatting();
  </code></pre>
  
  <p>From your plugins init function or where ever you would like to call it. </p>
  
  <p>Edit:</p>
  
  <p>I hope your <code>DateFormatting</code> is not like you posted it because it has no functions. Btw <code>Craft::import()</code> has the advantage that you can import entire folders and it loads the class only to Yiis classmap which means that it is only loaded when you need it and not until then. If you want to use the file for sure, require once is the better way since Craft/Yii does the same in the very end. </p>
  
  <p>Edit2:</p>
  
  <p>Never mind, Yii uses <code>include</code> and not <code>require_once</code>, sry for the wrong info here. However... today the difference is not that big issue. <a href="https://stackoverflow.com/a/186386/5604055">Comparison include vs require_once</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-06T19:21:13.630Z
Answers.LastActivityDate: 2018-03-06T19:57:42.813Z
Answers.LastEditDate: 2018-03-06T19:57:42.813Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I currently am developing a plugin to gather XML restful data. 
  At one point in the file, I need to reference another PHP file, which will process various data.  </p>
  
  <p>As a test, the code in the included file should return output, as well (see code below).</p>
  
  <p>I've tried to utilize the following code, but it doesn't work.  There is no error message, but again there is no data output.  </p>
  
  <pre><code>Craft::import('plugins.aifeed.resources.Date_Formatting');
  </code></pre>
  
  <p>I've been looking <a href="https://craftcms.stackexchange.com/questions/21512/using-craftimport-to-include-external-resource-into-the-craft-namespace/21521#">here</a>, but it wasn't clear to me how or if the 'included' file could be utilized.
  Thanks for any leads.</p>
  
  <p>Here is my code:</p>
  
  <p>in Variables folder:
  AiFeedVariable.php</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  class AiFeedVariable
  {
          public function XmlVariable($optional = null)
      {
  ....
  $strSampleDate = '2015-12-23';
  
  Craft::import('plugins.aifeed.resources.Date_Formatting');
  
  }
  }
  </code></pre>
  
  <p>in Resources folder:
  DateFormatting.php</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  class DateFormatting
  {
  $strDate_A=$strSampleDate;
  echo '$strDate_A test...'.$strDate_A.'&lt;br&gt;';
  }
  </code></pre>
  
Tags: <plugin-development><php>
Title: Include PHP file in plugin
ThreadText: # Include PHP file in plugin
  
  (Asked by: username_0 on 2018-03-06)
  
  I currently am developing a plugin to gather XML restful data.
  At one point in the file, I need to reference another PHP file, which will process various data.
  
  As a test, the code in the included file should return output, as well (see code below).
  
  I've tried to utilize the following code, but it doesn't work. There is no error message, but again there is no data output.
  
  ```
  Craft::import('plugins.aifeed.resources.Date_Formatting');
  
  ```
  
  I've been looking [here](https://craftcms.stackexchange.com/questions/21512/using-craftimport-to-include-external-resource-into-the-craft-namespace/21521#), but it wasn't clear to me how or if the 'included' file could be utilized.
  Thanks for any leads.
  
  Here is my code:
  
  in Variables folder:
  AiFeedVariable.php
  
  ```
  <?php
  namespace Craft;
  
  class AiFeedVariable
  {
          public function XmlVariable($optional = null)
      {
  ....
  $strSampleDate = '2015-12-23';
  
  Craft::import('plugins.aifeed.resources.Date_Formatting');
  
  }
  }
  
  ```
  
  in Resources folder:
  DateFormatting.php
  
  ```
  <?php
  namespace Craft;
  
  class DateFormatting
  {
  $strDate_A=$strSampleDate;
  echo '$strDate_A test...'.$strDate_A.'<br>';
  }
  
  ```
  
  **Tags:** plugin-development, php
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-03-06. Score: 2 | Accepted answer
  
  You can simply load the file normally via php [require once](http://php.net/manual/en/function.require-once.php)
  
  ```
  require_once( __DIR__ . '/resources/DateFormatting.php');
  $dataFormatter = new DateFormatting();
  
  ```
  
  From your plugins init function or where ever you would like to call it.
  
  Edit:
  
  I hope your `DateFormatting` is not like you posted it because it has no functions. Btw `Craft::import()` has the advantage that you can import entire folders and it loads the class only to Yiis classmap which means that it is only loaded when you need it and not until then. If you want to use the file for sure, require once is the better way since Craft/Yii does the same in the very end.
  
  Edit2:
  
  Never mind, Yii uses `include` and not `require_once`, sry for the wrong info here. However... today the difference is not that big issue. [Comparison include vs require\_once](https://stackoverflow.com/a/186386/5604055)
  
  
  ---
  
  