PHPackages                             kitano/php-expression - 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. kitano/php-expression

ActiveLibrary

kitano/php-expression
=====================

PHP Expression language

301.2k3[2 issues](https://github.com/Kitano/php-expression/issues)PHP

Since Sep 2Pushed 12y ago6 watchersCompare

[ Source](https://github.com/Kitano/php-expression)[ Packagist](https://packagist.org/packages/kitano/php-expression)[ RSS](/packages/kitano-php-expression/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Expression Language
=======================

[](#php-expression-language)

The purpose of this library is to provide a common base for an PHP Expression Language.

This is not really a creative library since it burrows almost all the code from the great [JMSSecurityExtraBundle](http://jmsyst.com/bundles/JMSSecurityExtraBundle) which already defines more or less such a base for a powerful EL (Expression Language).

The idea is to take this code outside of the Johannes's bundle and to standardize it.

Simple usage
------------

[](#simple-usage)

```
$compiler = new ExpressionCompiler();
$evaluator = eval($compiler->compileExpression(new Expression("date.format(format)")));

$context = array(
    'date' => new \DateTime(),
    'format' => 'Y',
);
$result = $evaluator($context);

echo $result; // 2013
```

Adding a custom function compiler
---------------------------------

[](#adding-a-custom-function-compiler)

The isNumber() function expression:

1. First you need to create a compiler for your function

    ```
