https://github.com/tysonandre/shortvarexport
Builds a small representation of PHP values as PHP code, similar to `var_export`, but with square brackets and less whitespace
https://github.com/tysonandre/shortvarexport
php var-export
Last synced: 8 months ago
JSON representation
Builds a small representation of PHP values as PHP code, similar to `var_export`, but with square brackets and less whitespace
- Host: GitHub
- URL: https://github.com/tysonandre/shortvarexport
- Owner: TysonAndre
- License: bsd-3-clause
- Created: 2017-06-09T04:45:40.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-12T20:14:54.000Z (about 9 years ago)
- Last Synced: 2025-10-09T02:46:16.354Z (8 months ago)
- Topics: php, var-export
- Language: PHP
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ShortVarExport
==============
Introduction
------------
Builds a smaller representation of PHP values as PHP code, similar to `var_export`.
The representation is also valid, executable PHP code.
This is compatible with PHP 7.0+ (Will work in php5 if you remove scalar type hints and return types, and `declare`)
- See https://github.com/TysonAndre/Transphpile to automatically convert code
`ShortVarExport\Builder::build($value)` returns arrays formatted with the php 5.4 square bracket syntax.
This isn't fully tested yet.
Supported data types:
- arrays
- scalars (string/float/int/bool)
- null
Unsupported data types, which will trigger an `InvalidArgumentException` (Support can be added by subclassing the class)
(A subclass may be added in the future, supporting objects)
- resource
- objects
License: MIT
Examples of things this could be used for:
- https://blog.graphiq.com/500x-faster-caching-than-redis-memcache-apc-in-php-hhvm-dcd26e8447ad
Usage
-----
```php
require_once '/path/to/Builder.php';
use ShortVarExport\Builder;
echo Builder::build(2, Builder::MULTI_LINE), "\n\n";
echo Builder::build(["value", 42, 4 => [["newvalue"]], "key" => "othervalue"], Builder::MULTI_LINE), "\n";
```
Output
```
2
[
"value",
4 => [["newvalue"]],
"key" => "othervalue",
]
```
Testing
-------
`php BuilderTest.php`