# PHP Include other code, How!?!?

**URL:** <https://community.dreamfactory.com/t/php-include-other-code-how/4522>\
**Category:** Server-Side Scripting\
**Created:** [July 11, 2018, 10:47pm UTC](https://community.dreamfactory.com/t/php-include-other-code-how/4522 "2018-07-11T22:47:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexr03](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/alexr03/32/1186_2.png) [@Alexr03](https://community.dreamfactory.com/u/Alexr03)\
**Post date:** [July 11, 2018, 10:47pm UTC](https://community.dreamfactory.com/t/php-include-other-code-how/4522/1 "2018-07-11T22:47:18Z")

</div>

Hi all!

I’m currently experiencing an issue where I need to use some PHP code outside of Dreamfactory.  
I am currently unable to do so as I keep receiving this error  
`[2018-07-11 22:22:53] local.ERROR: Class 'SourceQuery' not found {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Class 'SourceQuery' not found at C:\\Bitnami\\dreamfactory-2.12.0-1\\apps\\dreamfactory\\htdocs\\vendor\\dreamfactory\\df-script\\src\\Engines\\Php.php(49) : eval()'d code:34)"}`

This is part of the code experiencing the issues: [https://i.Alexr03.com/kid39sG88284.png](https://i.Alexr03.com/kid39sG88284.png)

How would I use the require and use that class as so I have heard Dreamfactory will not allow you to use require or use statements.

Many Thanks!

---

<div class="post-metadata">

**Author:** ![LBat](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/lbat/32/1004_2.png) [@LBat](https://community.dreamfactory.com/u/LBat)\
**Post date:** [July 20, 2018, 1:12pm UTC](https://community.dreamfactory.com/t/php-include-other-code-how/4522/2 "2018-07-20T13:12:47Z")

</div>

Hello,

The Path to your script may wrong, I have a external file to my scripts and have to put the correct path to get to work.

I put my file here:  
`.../dreamfactory/storage/scripting/myscripts.inc.php`

and in the dreamfactory put:  
`include(dirname(dirname( __FILE__ ))."/../../../../storage/scripting/myscripts.inc.php");`

Your can log the path and try until get the correct path to your file.

Regards,  
LBat

---

<div class="post-metadata">

**Author:** ![Erik\_Jacobsen](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/erik_jacobsen/32/1132_2.png) [@Erik\_Jacobsen](https://community.dreamfactory.com/u/Erik_Jacobsen)\
**Post date:** [July 20, 2018, 4:46pm UTC](https://community.dreamfactory.com/t/php-include-other-code-how/4522/3 "2018-07-20T16:46:01Z")

</div>

Just to add to this discussion:

You cannot use `use` or `require` as per our docs:

Including Other Scripts  
Currently, PHP scripts can not directly include other PHP code via `require()` methods or `use` statements as you normally would. However, DreamFactory can access any other code installed in the system by using fully qualified name-spaced class names.

The best way to bring in libraries is to use `composer require` on the package, and that will make it accessible via the code installed in the system by using fully qualified name-spaced class names.

For instance:

For example, run:

`$ composer require abraham/twitteroauth`

Then in your script reference `$connection = new \Abraham\TwitterOAuth\TwitterOAuth("...`

[![CloudApp](https://d3vv6lp55qjaqc.cloudfront.net/items/211m1O1g2n183v0N0I3B/Image%202018-07-13%20at%2010.30.59%20AM.png "Image 2018-07-13 at 10.30.59 AM.png") ](https://cl.ly/060w013P1k2B)

> **[TwitterOAuth PHP Library for the Twitter REST API](https://twitteroauth.com/)**
>
> The most popular PHP library for use with the Twitter OAuth REST API

BTW, here is a great tutorial to deploy custom scripts in DreamFactory:  
[http://www.devops-blog.net/dreamfactory/managing-and-deploying-custom-php-services-in-dreamfactory](http://www.devops-blog.net/dreamfactory/managing-and-deploying-custom-php-services-in-dreamfactory)
