3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function __(array &$class, string $member, ...$args) { if(!isset($class[$member])) exit($member.' is not a member of the class.'); else { if(!is_callable($class[$member])) return $class[$member]; else { if(!isset($args[0])) $class[$member]($class); else $class[$member]($class, $args); } } } function _new(array $class, ...$args) { $obj = $class; if(isset($class['__construct'])) { if(isset($args[0])) $obj['__construct']($obj, $args); else $obj['__construct']($obj); } return $obj; } $class = [ 'foo' => '', 'bar' => function (&$this) { $this['foo'] = ' World!'; }, '__construct' => function (&$this) { $this['foo'] = 'Hello'; } ]; $obj = _new($class); echo($obj['foo']); __($obj, 'bar'); echo($obj['foo']);
based on SGmGp
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/30iDI
function name:  (null)
number of ops:  21
compiled vars:  !0 = $class, !1 = $obj
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   NOP                                                      
  12     1        NOP                                                      
  22     2        INIT_ARRAY                                       ~2      '', 'foo'
  23     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F30iDI0x7fe549bf62ab'
  25     4        ADD_ARRAY_ELEMENT                                ~2      ~3, 'bar'
  26     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F30iDI0x7fe549bf62fb'
  28     6        ADD_ARRAY_ELEMENT                                ~2      ~4, '__construct'
         7        ASSIGN                                                   !0, ~2
  30     8        INIT_FCALL                                               '_new'
         9        SEND_VAR                                                 !0
        10        DO_FCALL                                      0  $6      
        11        ASSIGN                                                   !1, $6
  31    12        FETCH_DIM_R                                      $8      !1, 'foo'
        13        ECHO                                                     $8
  32    14        INIT_FCALL                                               '__'
        15        SEND_REF                                                 !1
        16        SEND_VAL                                                 'bar'
        17        DO_FCALL                                      0          
  33    18        FETCH_DIM_R                                      $10     !1, 'foo'
        19        ECHO                                                     $10
        20      > RETURN                                                   1

Function __:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
Jump found. Position 1 = -2
Branch analysis from position: 9
Jump found. Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
Jump found. Position 1 = -2
Branch analysis from position: 18
Jump found. Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
Jump found. Position 1 = 31
Branch analysis from position: 31
Jump found. Position 1 = -2
Branch analysis from position: 26
Jump found. Position 1 = -2
filename:       /in/30iDI
function name:  __
number of ops:  32
compiled vars:  !0 = $class, !1 = $member, !2 = $args
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   RECV                                             !0      
         1        RECV                                             !1      
         2        RECV_VARIADIC                                    !2      
   3     3        ISSET_ISEMPTY_DIM_OBJ                       33554432  ~3      !0, !1
         4        BOOL_NOT                                         ~4      ~3
         5      > JMPZ                                                     ~4, ->9
         6    >   CONCAT                                           ~5      !1, '+is+not+a+member+of+the+class.'
         7      > EXIT                                                     ~5
         8*       JMP                                                      ->31
   5     9    >   INIT_FCALL                                               'is_callable'
        10        FETCH_DIM_R                                      $6      !0, !1
        11        SEND_VAR                                                 $6
        12        DO_ICALL                                         $7      
        13        BOOL_NOT                                         ~8      $7
        14      > JMPZ                                                     ~8, ->18
        15    >   FETCH_DIM_R                                      $9      !0, !1
        16      > RETURN                                                   $9
        17*       JMP                                                      ->31
   7    18    >   ISSET_ISEMPTY_DIM_OBJ                       33554432  ~10     !2, 0
        19        BOOL_NOT                                         ~11     ~10
        20      > JMPZ                                                     ~11, ->26
        21    >   FETCH_DIM_R                                      $12     !0, !1
        22        INIT_DYNAMIC_CALL                                        $12
        23        SEND_VAR_EX                                              !0
        24        DO_FCALL                                      0          
        25      > JMP                                                      ->31
   8    26    >   FETCH_DIM_R                                      $14     !0, !1
        27        INIT_DYNAMIC_CALL                                        $14
        28        SEND_VAR_EX                                              !0
        29        SEND_VAR_EX                                              !2
        30        DO_FCALL                                      0          
  11    31    > > RETURN                                                   null

End of function __

Function _new:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 5, Position 2 = 17
Branch analysis from position: 5
Jump found. Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
Jump found. Position 1 = 17
Branch analysis from position: 17
Jump found. Position 1 = -2
Branch analysis from position: 13
Jump found. Position 1 = -2
Branch analysis from position: 17
filename:       /in/30iDI
function name:  _new
number of ops:  19
compiled vars:  !0 = $class, !1 = $args, !2 = $obj
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  12     0  E >   RECV                                             !0      
         1        RECV_VARIADIC                                    !1      
  13     2        ASSIGN                                                   !2, !0
  14     3        ISSET_ISEMPTY_DIM_OBJ                       33554432  ~4      !0, '__construct'
         4      > JMPZ                                                     ~4, ->17
  15     5    >   ISSET_ISEMPTY_DIM_OBJ                       33554432  ~5      !1, 0
         6      > JMPZ                                                     ~5, ->13
         7    >   FETCH_DIM_R                                      $6      !2, '__construct'
         8        INIT_DYNAMIC_CALL                                        $6
         9        SEND_VAR_EX                                              !2
        10        SEND_VAR_EX                                              !1
        11        DO_FCALL                                      0          
        12      > JMP                                                      ->17
  16    13    >   FETCH_DIM_R                                      $8      !2, '__construct'
        14        INIT_DYNAMIC_CALL                                        $8
        15        SEND_VAR_EX                                              !2
        16        DO_FCALL                                      0          
  18    17    > > RETURN                                                   !2
  19    18*     > RETURN                                                   null

End of function _new

Function %00%7Bclosure%7D%2Fin%2F30iDI0x7fe549bf62ab:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/30iDI
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  23     0  E >   RECV                                             !0      
  24     1        ASSIGN_DIM                                               !0, 'foo'
         2        OP_DATA                                                  '+World%21'
  25     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F30iDI0x7fe549bf62ab

Function %00%7Bclosure%7D%2Fin%2F30iDI0x7fe549bf62fb:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/30iDI
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  26     0  E >   RECV                                             !0      
  27     1        ASSIGN_DIM                                               !0, 'foo'
         2        OP_DATA                                                  'Hello'
  28     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F30iDI0x7fe549bf62fb

Generated using Vulcan Logic Dumper, using php 7.3.0