3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function createFunction($formula, $args) { $func = function ($args) use ($formula) { foreach ($args as $key => $val) { $$key = $val; } return eval($formula); }; return $func($args); } } $foo = new Foo; $formula = <<<'EOT' if($a == 'some_value' || $c == 'other_value') { return 'something'; } else if($b == 'something' && $d == 'anything') { return 'something_else'; } else { return 'anything'; } EOT; echo $foo->createFunction($formula, ['a' => 'some_value', 'b' => '', 'c' => 'other_value', 'd' => 'anything']); echo "\n"; echo $foo->createFunction($formula, ['a' => '', 'b' => 'something', 'c' => '', 'd' => 'anything']); echo "\n"; echo $foo->createFunction($formula, ['a' => '', 'b' => '', 'c' => '', 'd' => '']);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HrMKN
function name:  (null)
number of ops:  22
compiled vars:  !0 = $foo, !1 = $formula
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $2      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   19     3        ASSIGN                                                   !1, 'if%28%24a+%3D%3D+%27some_value%27+%7C%7C+%24c+%3D%3D+%27other_value%27%29+%7B%0A++++return+%27something%27%3B%0A%7D+else+if%28%24b+%3D%3D+%27something%27+%26%26+%24d+%3D%3D+%27anything%27%29+%7B%0A++++return+%27something_else%27%3B%0A%7D+else+%7B%0A++++return+%27anything%27%3B%0A%7D'
   29     4        INIT_METHOD_CALL                                         !0, 'createFunction'
          5        SEND_VAR_EX                                              !1
          6        SEND_VAL_EX                                              <array>
          7        DO_FCALL                                      0  $6      
          8        ECHO                                                     $6
   30     9        ECHO                                                     '%0A'
   31    10        INIT_METHOD_CALL                                         !0, 'createFunction'
         11        SEND_VAR_EX                                              !1
         12        SEND_VAL_EX                                              <array>
         13        DO_FCALL                                      0  $7      
         14        ECHO                                                     $7
   32    15        ECHO                                                     '%0A'
   33    16        INIT_METHOD_CALL                                         !0, 'createFunction'
         17        SEND_VAR_EX                                              !1
         18        SEND_VAL_EX                                              <array>
         19        DO_FCALL                                      0  $8      
         20        ECHO                                                     $8
         21      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FHrMKN%3A7%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/HrMKN
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $args, !1 = $formula, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    8     2      > FE_RESET_R                                       $4      !0, ->8
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->8
          4    >   ASSIGN                                                   !3, ~5
    9     5        FETCH_W                      local               $7      !3
          6        ASSIGN                                                   $7, !2
    8     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $4
   11     9        INCLUDE_OR_EVAL                                  $9      !1, EVAL
         10      > RETURN                                                   $9
   12    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHrMKN%3A7%240

Class Foo:
Function createfunction:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HrMKN
function name:  createFunction
number of ops:  10
compiled vars:  !0 = $formula, !1 = $args, !2 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHrMKN%3A7%240'
          3        BIND_LEXICAL                                             ~3, !0
          4        ASSIGN                                                   !2, ~3
   13     5        INIT_DYNAMIC_CALL                                        !2
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $5      
          8      > RETURN                                                   $5
   14     9*     > RETURN                                                   null

End of function createfunction

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.16 ms | 1403 KiB | 13 Q