PHP code example of mf / callback-parser

1. Go to this page and download the library: Download mf/callback-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mf / callback-parser example snippets


$callbackParser = new CallbackParser();
$callback = $callbackParser->parseArrowFunction('($a, $b) => $a + $b');

var_dump($callback(2, 3));  // int 5

$callbackParser = new CallbackParser(App\MyCustomException::class);

$callbackParser->parseArrowFunction('invalid');  // throws App\MyCustomException

(SimpleEntity $entity) => $entity->getId()

$list = new Generic\ListCollection(SimpleEntity::class);
$list->add(new SimpleEntity(1));
$list->add(new SimpleEntity(2));

$ids = $list->map('($entity) => $entity->getId()');

var_dump($ids);

//array (size=2)
//  0 => int 1
//  1 => int 2