Virtual eval

1.0.0 2014-09-07 14:03 UTC

This package is not auto-updated.

Last update: 2023-03-13 19:12:35 UTC


Virtual Eval

Master branch build status Published version PHP ~5.4 MIT Licensed

Veval is an implementation of eval that uses a virtual file system to store code for evaluation and then require it back out. It should work on PHP installations that don't support or have disabled native eval.

It can be installed in whichever way you prefer, but I recommend Composer.

    "require": {
        "adlawson/veval": "*"


The Veval API is exposed as a collection of Veval\ namespaced functions, though you may prefer to use Veval:: to take advantage of autoloading and namespace aliasing (PHP < 5.6).


// Evaluate some code
class Foo {
    public $name;
    public function __construct($name) {$this->name = $name;}

// Use your newly evaulated code
$foo = new Foo('bar');
$foo->name; // bar


Storing all of the "files" in memory is all fine if your evaluated code is workng as you expect, but sometimes it's useful to read the generated code to debug any problems. There are a few different debugging functions available to suit your needs.


// Debug all evaluated strings
Veval\debug(function ($name, $content) {
    // Debug some things here

// Iterate over all evaulated strings
foreach (Veval\iterator() as $name => $content) {
    // Debug some things here

// Dump all to path
Veval\dump(sys_get_temp_dir(), 'veval-%s.php');


Eval Warning

Using **Veval**, just like eval, is considered dangerous to use if you're evaluating user input. Always be careful not to do this as it can open up quite a large hole in the security of your system.


Contributions are accepted via Pull Request, but passing unit tests must be included before it will be considered for merge.

$ curl -O
$ vagrant up
$ vagrant ssh

$ cd /srv
$ composer install
$ vendor/bin/phpunit


The content of this library is released under the MIT License by Andrew Lawson.
You can find a copy of this license in LICENSE or at