PHPackages                             riimu/kit-phpencoder - 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. riimu/kit-phpencoder

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

riimu/kit-phpencoder
====================

Highly customizable alternative to var\_export for PHP code generation

v2.4.2(3y ago)717.8M—9%4[2 issues](https://github.com/Riimu/Kit-PHPEncoder/issues)20MITPHPPHP &gt;=5.6.0

Since Nov 1Pushed 3y ago5 watchersCompare

[ Source](https://github.com/Riimu/Kit-PHPEncoder)[ Packagist](https://packagist.org/packages/riimu/kit-phpencoder)[ Docs](http://kit.riimu.net)[ RSS](/packages/riimu-kit-phpencoder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)DependenciesVersions (20)Used By (20)

PHP Variable Exporter
=====================

[](#php-variable-exporter)

*PHPEncoder* is a PHP library for exporting variables and generating PHP code representations for said variables similar to the built in function `var_export()`. Compared to the built in function, however, this library provides more options to customize the output, which makes it easier to generate code for different kinds of purposes such as readable configuration files or optimized cache files.

The purpose of this library is to address some of the shortcomings with the built in `var_export()`. For example, there is no way to control the amount of whitespace in the output and there is no way to choose between different array notations. This library also provides functionality to convert objects into PHP code that is actually useful when compared to the built in function.

The large number of customization options in this library allows you to create code that fits your purposes. You can create very compact code, when you need to limit the size of the output, or you can create code in the style that actually fits in any of your dynamically generated PHP files.

The API documentation is available at:

[![CI](https://camo.githubusercontent.com/8a4b5d49192037a5baddbb17f11c83c6c915de6890afd8b4bc26776096a2a234/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f5269696d752f4b69742d504850456e636f6465722f43492f6d61737465723f7374796c653d666c61742d737175617265)](https://github.com/Riimu/Kit-PHPEncoder/actions)[![Scrutinizer](https://camo.githubusercontent.com/81ba61a9871b15bcdce2d47317427fcba5f1bb6babb7b867bf3a401dd8f47992/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f5269696d752f4b69742d504850456e636f6465722f6d61737465723f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Riimu/Kit-PHPEncoder/)[![codecov](https://camo.githubusercontent.com/f377e867ec0024b68e98fef985366297ae193f67582e75d066eb62ca6c5f78ee/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f5269696d752f4b69742d504850456e636f6465722f6d61737465723f7374796c653d666c61742d737175617265)](https://codecov.io/gh/Riimu/Kit-PHPEncoder)[![Packagist](https://camo.githubusercontent.com/4c297c08cd602c7b65d62116507db73c3fc177c696d52da3cb92fa2b3069ff85/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7269696d752f6b69742d706870656e636f6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riimu/kit-phpencoder)

Requirements
------------

[](#requirements)

- The minimum supported PHP version is 5.6

Installation
------------

[](#installation)

### Installation with Composer

[](#installation-with-composer)

The easiest way to install this library is to use Composer to handle your dependencies. In order to install this library via Composer, simply follow these two steps:

1. Acquire the `composer.phar` by running the Composer [Command-line installation](https://getcomposer.org/download/)in your project root.
2. Once you have run the installation script, you should have the `composer.phar`file in you project root and you can run the following command:

    ```
    php composer.phar require "riimu/kit-phpencoder:^2.3"

    ```

After installing this library via Composer, you can load the library by including the `vendor/autoload.php` file that was generated by Composer during the installation.

### Adding the library as a dependency

[](#adding-the-library-as-a-dependency)

If you are already familiar with how to use Composer, you may alternatively add the library as a dependency by adding the following `composer.json` file to your project and running the `composer install` command:

```
{
    "require": {
        "riimu/kit-phpencoder": "^2.3"
    }
}
```

### Manual installation

[](#manual-installation)

If you do not wish to use Composer to load the library, you may also download the library manually by downloading the [latest release](https://github.com/Riimu/Kit-PHPEncoder/releases/latest)and extracting the `src` folder to your project. You may then include the provided `src/autoload.php` file to load the library classes.

Usage
-----

[](#usage)

The most relevant method provided by this library is the `encode()` method provided by `PHPEncoder`. The method takes any value as an argument and returns the PHP code representation for that value.

For example:

```
