3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Inflector { private $methods = []; public function __construct(array $methods) { $this->methods = $methods; //var_dump($this->methods); } public function __call(string $methodName, $test) { if (isset($this->methods[$methodName])) { return $this->methods[$methodName]($test); } throw new InflectionDeceptionException(); } } class InflectionDeceptionException extends \Exception { public function __construct($message = "Say what?") { return parent::__construct($message); } } $a = new Inflector([ 'foo' => function($val){echo sprintf('%s calls foo()', $val[0] ?? 'none!').PHP_EOL;}, 'bar' => function($val){echo sprintf('%s calls bar()', $val[0] ?? 'none!').PHP_EOL;}, 'baz' => function($val){echo sprintf('%s calls baz()', $val[0] ?? 'none!').PHP_EOL;}, ]); $a->foo('Ahnold'); $a->bar('Elvis'); $a->baz('Lerhman'); $a->theBreaks('Who');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kLdOp
function name:  (null)
number of ops:  23
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   NEW                                              $1      'Inflector'
   35     1        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          2        INIT_ARRAY                                       ~3      ~2, 'foo'
   36     3        DECLARE_LAMBDA_FUNCTION                          ~4      [1]
          4        ADD_ARRAY_ELEMENT                                ~3      ~4, 'bar'
   37     5        DECLARE_LAMBDA_FUNCTION                          ~5      [2]
          6        ADD_ARRAY_ELEMENT                                ~3      ~5, 'baz'
          7        SEND_VAL_EX                                              ~3
   34     8        DO_FCALL                                      0          
          9        ASSIGN                                                   !0, $1
   40    10        INIT_METHOD_CALL                                         !0, 'foo'
         11        SEND_VAL_EX                                              'Ahnold'
         12        DO_FCALL                                      0          
   41    13        INIT_METHOD_CALL                                         !0, 'bar'
         14        SEND_VAL_EX                                              'Elvis'
         15        DO_FCALL                                      0          
   42    16        INIT_METHOD_CALL                                         !0, 'baz'
         17        SEND_VAL_EX                                              'Lerhman'
         18        DO_FCALL                                      0          
   43    19        INIT_METHOD_CALL                                         !0, 'theBreaks'
         20        SEND_VAL_EX                                              'Who'
         21        DO_FCALL                                      0          
         22      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kLdOp
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 '%25s+calls+foo%28%29'
          3        FETCH_DIM_IS                                     ~1      !0, 0
          4        COALESCE                                         ~2      ~1
          5        QM_ASSIGN                                        ~2      'none%21'
          6        SEND_VAL                                                 ~2
          7        DO_ICALL                                         $3      
          8        CONCAT                                           ~4      $3, '%0A'
          9        ECHO                                                     ~4
         10      > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kLdOp
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 '%25s+calls+bar%28%29'
          3        FETCH_DIM_IS                                     ~1      !0, 0
          4        COALESCE                                         ~2      ~1
          5        QM_ASSIGN                                        ~2      'none%21'
          6        SEND_VAL                                                 ~2
          7        DO_ICALL                                         $3      
          8        CONCAT                                           ~4      $3, '%0A'
          9        ECHO                                                     ~4
         10      > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kLdOp
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 '%25s+calls+baz%28%29'
          3        FETCH_DIM_IS                                     ~1      !0, 0
          4        COALESCE                                         ~2      ~1
          5        QM_ASSIGN                                        ~2      'none%21'
          6        SEND_VAL                                                 ~2
          7        DO_ICALL                                         $3      
          8        CONCAT                                           ~4      $3, '%0A'
          9        ECHO                                                     ~4
         10      > RETURN                                                   null

End of Dynamic Function 2

Class Inflector:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kLdOp
function name:  __construct
number of ops:  4
compiled vars:  !0 = $methods
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        ASSIGN_OBJ                                               'methods'
          2        OP_DATA                                                  !0
   12     3      > RETURN                                                   null

End of function __construct

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/kLdOp
function name:  __call
number of ops:  15
compiled vars:  !0 = $methodName, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        FETCH_OBJ_IS                                     ~2      'methods'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~2, !0
          4      > JMPZ                                                     ~3, ->11
   17     5    >   FETCH_OBJ_R                                      ~4      'methods'
          6        FETCH_DIM_R                                      ~5      ~4, !0
          7        INIT_DYNAMIC_CALL                                        ~5
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0  $6      
         10      > RETURN                                                   $6
   20    11    >   NEW                                              $7      'InflectionDeceptionException'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $7
   21    14*     > RETURN                                                   null

End of function __call

End of class Inflector.

Class InflectionDeceptionException:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kLdOp
function name:  __construct
number of ops:  6
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV_INIT                                        !0      'Say+what%3F'
   29     1        INIT_STATIC_METHOD_CALL                                  
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   30     5*     > RETURN                                                   null

End of function __construct

End of class InflectionDeceptionException.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.95 ms | 1019 KiB | 14 Q