PHPackages                             brad-jones/import - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. brad-jones/import

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

brad-jones/import
=================

Includes a PHP file in such a way as to isolate it from where it was included.

v0.0.4(10y ago)0801MITPHP

Since Feb 22Pushed 10y ago1 watchersCompare

[ Source](https://github.com/brad-jones/import)[ Packagist](https://packagist.org/packages/brad-jones/import)[ Docs](https://github.com/brad-jones/import)[ RSS](/packages/brad-jones-import/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (1)Versions (5)Used By (1)

Brads PHP File Importer
=======================

[](#brads-php-file-importer)

[![Build Status](https://camo.githubusercontent.com/85091f0df86e84117cfe2166438bc261916ad2b0488d0c1fb9b79dd1ff0c6bf8/68747470733a2f2f7472617669732d63692e6f72672f627261642d6a6f6e65732f696d706f72742e737667)](https://travis-ci.org/brad-jones/import)[![Latest Stable Version](https://camo.githubusercontent.com/d74dccb6f4cf2b28131121096a46ca7afb093dff42cbfa729942378940c293be/68747470733a2f2f706f7365722e707567782e6f72672f627261642d6a6f6e65732f696d706f72742f762f737461626c652e737667)](https://packagist.org/packages/brad-jones/import)[![Total Downloads](https://camo.githubusercontent.com/336e76d7f30cff6064c4a556f11b30e233cf59a6c0a499c08a5ebe5d35179a67/68747470733a2f2f706f7365722e707567782e6f72672f627261642d6a6f6e65732f696d706f72742f646f776e6c6f6164732e737667)](https://packagist.org/packages/brad-jones/import)[![License](https://camo.githubusercontent.com/a059aefe6da24cf420e528fa227b45598d87d62fe5987cbcd23f9a6f74f46861/68747470733a2f2f706f7365722e707567782e6f72672f627261642d6a6f6e65732f696d706f72742f6c6963656e73652e737667)](https://packagist.org/packages/brad-jones/import)[![HHVM Tested](https://camo.githubusercontent.com/0cdef27751b13540acd2fb599f2b52428f96000d7c9a3daad9b95a0920cf5a9a/687474703a2f2f6868766d2e683463632e64652f62616467652f627261642d6a6f6e65732f696d706f72742e7376673f7374796c653d666c6174)](http://hhvm.h4cc.de/package/brad-jones/import)

Includes a PHP file in such a way as to isolate it from where it was included. This package provides a new pseudo language construct, you will be familiar with how `include` and `require` work, well we have now added `import`.

Credit:

Installation:
-------------

[](#installation)

```
composer require brad-jones/import

```

Getting access to the import function:
--------------------------------------

[](#getting-access-to-the-import-function)

There are various ways you can access the import function.

- If using PHP 5.6 or greater, you can import the import function.

    ```
    use function Brads\import;
    import(...args...);
    ```
- Or you can call the static method on the Importer class.

    ```
    use Brads\Importer;
    Importer::import(...args...);
    ```
- Or you can create an instance of the Importer.

    ```
    use Brads\Importer;
    $importer = new Importer;
    $importer->newImport(...args...);
    ```
- Or if you would rather install the import function globally.

    ```
    Brads\Importer::globalise();
    import(...args...);
    ```

Dependency Injection:
---------------------

[](#dependency-injection)

The importer is Di &amp; Test friendly, it implements the ImporterInterface.

A simple contrived [php-di](http://php-di.org/) example:

```
use Brads\Importer;
use Brads\ImporterInterface;

$builder = new DI\ContainerBuilder();
$builder->addDefinitions
([
    ImporterInterface::class => DI\object(Importer::class)
]);
$container = $builder->build();

$container->get(ImporterInterface::class)->newImport(...args...);
```

Example Usage:
--------------

[](#example-usage)

Firstly for these examples assume the contents of `foo.php` is:

```

```

Secondly assume we are just using the globalised import function. Regardless of how you access it the result is the same.

### Exported Value:

[](#exported-value)

The import function will return any value that is returned by the imported file. Just the same as `include` or `require`. When combined with closures and a di container, you can end up with something akin to the node.js CommonJs module system.

```
$exported = import('foo.php');
```

### Isolated Import:

[](#isolated-import)

The whole point of this project is to ensure the imported file does not have access to any variables from the parent file. So with a normal `include`or `require` you would have something like this:

```
$abc = '123';
$exported = include('foo.php');
var_dump($exported == ['abc' => '123']); // true
```

With our import function this is what happens:

```
$abc = '123';
$exported = include('foo.php');
var_dump($exported == []); // true
```

### Providing a Custom Scope:

[](#providing-a-custom-scope)

Sometimes we might want the imported file to have access to some specific data.

```
$abc = '123';
$scope = ['bar' => 'baz'];
$exported = include('foo.php', $scope);
var_dump($exported == $scope); // true
```

### Include or Require:

[](#include-or-require)

Under the hood import does use the normal `include` or `require`.
By default we use `require` but you can changes this easily.

```
import('foo.php', null, true);  // requires foo.php
import('foo.php', null, false); // includes foo.php
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

3778d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2754772?v=4)[Brad Jones](/maintainers/brad-jones)[@brad-jones](https://github.com/brad-jones)

---

Top Contributors

[![brad-jones](https://avatars.githubusercontent.com/u/2754772?v=4)](https://github.com/brad-jones "brad-jones (12 commits)")

---

Tags

importisolateincluderequire

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/brad-jones-import/health.svg)

```
[![Health](https://phpackages.com/badges/brad-jones-import/health.svg)](https://phpackages.com/packages/brad-jones-import)
```

###  Alternatives

[konnco/filament-import

241248.5k2](/packages/konnco-filament-import)[anaseqal/nova-import

A Laravel Nova import tool.

70403.7k1](/packages/anaseqal-nova-import)[cleverage/process-bundle

Process, import/export, transform and validate data with a simple API with Symfony3

2153.1k13](/packages/cleverage-process-bundle)[evilfreelancer/openvpn-php

OpenVPN config generator writen on PHP

304.9k](/packages/evilfreelancer-openvpn-php)[konnco/filament-safely-delete

343.5k](/packages/konnco-filament-safely-delete)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
