New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

adlawson/veval

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adlawson/veval

Virtual eval

Source
Packagist
Version
1.0.0
Version published
Total downloads
149
Maintainers
1
Created
Source

Veval (Virtual eval)

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": "*"
    }
}

Documentation

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).

<?php

// Evaluate some code
Veval\execute(<<<'EOF'
class Foo {
    public $name;
    public function __construct($name) {$this->name = $name;}
}
EOF
);

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

Debugging

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.

<?php

// 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');

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.

Contributing

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

$ curl -O https://raw.githubusercontent.com/adlawson/vagrantfiles/master/php/Vagrantfile
$ vagrant up
$ vagrant ssh
...

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

License

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 http://opensource.org/licenses/mit.

Keywords

stream

FAQs

Package last updated on 07 Sep 2014

Related posts