3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Base{ protected $funcs = []; public function __call($name, $args) { echo("\t>>>Call [$name](". json_encode($args). ") \r\n"); if (method_exists($this, $name)) { return call_user_func_array($this->$name, $args); } else if (isset($this->funcs[ $name ])) { return call_user_func_array($this->funcs[ $name ], $args); } else { throw new Exception("Method <$name> is not accessible."); } } /** * @param array $args * * @example new Base(["field1"=>"value1", "field2"=>"value2"]) * if u need override __constructor, then use: * __construct($args){ * .. * parent::__construct($args); * } */ public function __construct($args = []) { $nameClass = get_class($this); #region auto create methods 'hasField' for everyone field\property (if there exists getter or setter) $properties = get_class_vars($nameClass); $keys = array_keys($properties); foreach ($keys AS $k) { if ((method_exists($this, "set" . ucfirst($k)) || method_exists($this, "get" . ucfirst($k))) && (!method_exists($this, "has" . ucfirst($k) && !isset($this->funcs["has" . ucfirst($k)]))) ) { $v = &$this->$k; $this->funcs["has" . ucfirst($k)] = function () use (&$v) { return !empty($v); }; } } #endregion foreach ($args as $k => $v) { if (property_exists($nameClass, $k)) { $this->$k = $v; } } } } class Test extends Base{ protected $field1; public function setField1($v){$this->field1 = $v;} public function getField1(){return $this->field1;} } $test = new Test(); $test->setField1(23423); echo $test->hasField1();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kH7hD
function name:  (null)
number of ops:  10
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   NEW                                              $1      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   59     3        INIT_METHOD_CALL                                         !0, 'setField1'
          4        SEND_VAL_EX                                              23423
          5        DO_FCALL                                      0          
   60     6        INIT_METHOD_CALL                                         !0, 'hasField1'
          7        DO_FCALL                                      0  $5      
          8        ECHO                                                     $5
          9      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FkH7hD%3A38%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kH7hD
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   BIND_STATIC                                              !0
          1        ISSET_ISEMPTY_CV                                 ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FkH7hD%3A38%240

Class Base:
Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/kH7hD
function name:  __call
number of ops:  43
compiled vars:  !0 = $name, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ROPE_INIT                                     3  ~3      '%09%3E%3E%3ECall+%5B'
          3        ROPE_ADD                                      1  ~3      ~3, !0
          4        ROPE_END                                      2  ~2      ~3, '%5D%28'
          5        INIT_FCALL                                               'json_encode'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $5      
          8        CONCAT                                           ~6      ~2, $5
          9        CONCAT                                           ~7      ~6, '%29+%0D%0A'
         10        ECHO                                                     ~7
    8    11        INIT_FCALL                                               'method_exists'
         12        FETCH_THIS                                       ~8      
         13        SEND_VAL                                                 ~8
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $9      
         16      > JMPZ                                                     $9, ->24
    9    17    >   FETCH_OBJ_R                                      ~10     !0
         18        INIT_USER_CALL                                0          'call_user_func_array', ~10
         19        SEND_ARRAY                                               !1
         20        CHECK_UNDEF_ARGS                                         
         21        DO_FCALL                                      0  $11     
         22      > RETURN                                                   $11
         23*       JMP                                                      ->42
   10    24    >   FETCH_OBJ_IS                                     ~12     'funcs'
         25        ISSET_ISEMPTY_DIM_OBJ                         0          ~12, !0
         26      > JMPZ                                                     ~13, ->35
   11    27    >   FETCH_OBJ_R                                      ~14     'funcs'
         28        FETCH_DIM_R                                      ~15     ~14, !0
         29        INIT_USER_CALL                                0          'call_user_func_array', ~15
         30        SEND_ARRAY                                               !1
         31        CHECK_UNDEF_ARGS                                         
         32        DO_FCALL                                      0  $16     
         33      > RETURN                                                   $16
         34*       JMP                                                      ->42
   13    35    >   NEW                                              $17     'Exception'
         36        ROPE_INIT                                     3  ~19     'Method+%3C'
         37        ROPE_ADD                                      1  ~19     ~19, !0
         38        ROPE_END                                      2  ~18     ~19, '%3E+is+not+accessible.'
         39        SEND_VAL_EX                                              ~18
         40        DO_FCALL                                      0          
         41      > THROW                                         0          $17
   15    42*     > RETURN                                                   null

End of function __call

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 68
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 68
Branch analysis from position: 14
2 jumps found. (Code = 47) Position 1 = 24, Position 2 = 34
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 55
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 43, Position 2 = 51
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 67
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 67
Branch analysis from position: 51
Branch analysis from position: 55
Branch analysis from position: 34
Branch analysis from position: 68
2 jumps found. (Code = 77) Position 1 = 70, Position 2 = 80
Branch analysis from position: 70
2 jumps found. (Code = 78) Position 1 = 71, Position 2 = 80
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 79
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 79
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
Branch analysis from position: 68
filename:       /in/kH7hD
function name:  __construct
number of ops:  82
compiled vars:  !0 = $args, !1 = $nameClass, !2 = $properties, !3 = $keys, !4 = $k, !5 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV_INIT                                        !0      <array>
   28     1        FETCH_THIS                                       ~6      
          2        GET_CLASS                                        ~7      ~6
          3        ASSIGN                                                   !1, ~7
   31     4        INIT_FCALL                                               'get_class_vars'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !2, $9
   32     8        INIT_FCALL                                               'array_keys'
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !3, $11
   33    12      > FE_RESET_R                                       $13     !3, ->68
         13    > > FE_FETCH_R                                               $13, !4, ->68
   34    14    >   INIT_FCALL                                               'method_exists'
         15        FETCH_THIS                                       ~14     
         16        SEND_VAL                                                 ~14
         17        INIT_FCALL                                               'ucfirst'
         18        SEND_VAR                                                 !4
         19        DO_ICALL                                         $15     
         20        CONCAT                                           ~16     'set', $15
         21        SEND_VAL                                                 ~16
         22        DO_ICALL                                         $17     
         23      > JMPNZ_EX                                         ~18     $17, ->34
         24    >   INIT_FCALL                                               'method_exists'
         25        FETCH_THIS                                       ~19     
         26        SEND_VAL                                                 ~19
         27        INIT_FCALL                                               'ucfirst'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $20     
         30        CONCAT                                           ~21     'get', $20
         31        SEND_VAL                                                 ~21
         32        DO_ICALL                                         $22     
         33        BOOL                                             ~18     $22
         34    > > JMPZ_EX                                          ~18     ~18, ->55
   35    35    >   INIT_FCALL                                               'method_exists'
         36        FETCH_THIS                                       ~23     
         37        SEND_VAL                                                 ~23
         38        INIT_FCALL                                               'ucfirst'
         39        SEND_VAR                                                 !4
         40        DO_ICALL                                         $24     
         41        CONCAT                                           ~25     'has', $24
         42      > JMPZ_EX                                          ~25     ~25, ->51
         43    >   INIT_FCALL                                               'ucfirst'
         44        SEND_VAR                                                 !4
         45        DO_ICALL                                         $27     
         46        CONCAT                                           ~28     'has', $27
         47        FETCH_OBJ_IS                                     ~26     'funcs'
         48        ISSET_ISEMPTY_DIM_OBJ                         0  ~29     ~26, ~28
         49        BOOL_NOT                                         ~30     ~29
         50        BOOL                                             ~25     ~30
         51    >   SEND_VAL                                                 ~25
         52        DO_ICALL                                         $31     
         53        BOOL_NOT                                         ~32     $31
         54        BOOL                                             ~18     ~32
         55    > > JMPZ                                                     ~18, ->67
   37    56    >   FETCH_OBJ_W                                      $33     !4
         57        ASSIGN_REF                                               !5, $33
   38    58        INIT_FCALL                                               'ucfirst'
         59        SEND_VAR                                                 !4
         60        DO_ICALL                                         $36     
         61        CONCAT                                           ~37     'has', $36
         62        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FkH7hD%3A38%240'
         63        BIND_LEXICAL                                             ~39, !5
         64        FETCH_OBJ_W                                      $35     'funcs'
         65        ASSIGN_DIM                                               $35, ~37
         66        OP_DATA                                                  ~39
   33    67    > > JMP                                                      ->13
         68    >   FE_FREE                                                  $13
   43    69      > FE_RESET_R                                       $40     !0, ->80
         70    > > FE_FETCH_R                                       ~41     $40, !5, ->80
         71    >   ASSIGN                                                   !4, ~41
   44    72        INIT_FCALL                                               'property_exists'
         73        SEND_VAR                                                 !1
         74        SEND_VAR                                                 !4
         75        DO_ICALL                                         $43     
         76      > JMPZ                                                     $43, ->79
   45    77    >   ASSIGN_OBJ                                               !4
         78        OP_DATA                                                  !5
   43    79    > > JMP                                                      ->70
         80    >   FE_FREE                                                  $40
   48    81      > RETURN                                                   null

End of function __construct

End of class Base.

Class Test:
Function setfield1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kH7hD
function name:  setField1
number of ops:  4
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'field1'
          2        OP_DATA                                                  !0
          3      > RETURN                                                   null

End of function setfield1

Function getfield1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kH7hD
function name:  getField1
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   FETCH_OBJ_R                                      ~0      'field1'
          1      > RETURN                                                   ~0
          2*     > RETURN                                                   null

End of function getfield1

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/kH7hD
function name:  __call
number of ops:  43
compiled vars:  !0 = $name, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ROPE_INIT                                     3  ~3      '%09%3E%3E%3ECall+%5B'
          3        ROPE_ADD                                      1  ~3      ~3, !0
          4        ROPE_END                                      2  ~2      ~3, '%5D%28'
          5        INIT_FCALL                                               'json_encode'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $5      
          8        CONCAT                                           ~6      ~2, $5
          9        CONCAT                                           ~7      ~6, '%29+%0D%0A'
         10        ECHO                                                     ~7
    8    11        INIT_FCALL                                               'method_exists'
         12        FETCH_THIS                                       ~8      
         13        SEND_VAL                                                 ~8
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $9      
         16      > JMPZ                                                     $9, ->24
    9    17    >   FETCH_OBJ_R                                      ~10     !0
         18        INIT_USER_CALL                                0          'call_user_func_array', ~10
         19        SEND_ARRAY                                               !1
         20        CHECK_UNDEF_ARGS                                         
         21        DO_FCALL                                      0  $11     
         22      > RETURN                                                   $11
         23*       JMP                                                      ->42
   10    24    >   FETCH_OBJ_IS                                     ~12     'funcs'
         25        ISSET_ISEMPTY_DIM_OBJ                         0          ~12, !0
         26      > JMPZ                                                     ~13, ->35
   11    27    >   FETCH_OBJ_R                                      ~14     'funcs'
         28        FETCH_DIM_R                                      ~15     ~14, !0
         29        INIT_USER_CALL                                0          'call_user_func_array', ~15
         30        SEND_ARRAY                                               !1
         31        CHECK_UNDEF_ARGS                                         
         32        DO_FCALL                                      0  $16     
         33      > RETURN                                                   $16
         34*       JMP                                                      ->42
   13    35    >   NEW                                              $17     'Exception'
         36        ROPE_INIT                                     3  ~19     'Method+%3C'
         37        ROPE_ADD                                      1  ~19     ~19, !0
         38        ROPE_END                                      2  ~18     ~19, '%3E+is+not+accessible.'
         39        SEND_VAL_EX                                              ~18
         40        DO_FCALL                                      0          
         41      > THROW                                         0          $17
   15    42*     > RETURN                                                   null

End of function __call

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 68
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 68
Branch analysis from position: 14
2 jumps found. (Code = 47) Position 1 = 24, Position 2 = 34
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 55
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 43, Position 2 = 51
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 67
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 67
Branch analysis from position: 51
Branch analysis from position: 55
Branch analysis from position: 34
Branch analysis from position: 68
2 jumps found. (Code = 77) Position 1 = 70, Position 2 = 80
Branch analysis from position: 70
2 jumps found. (Code = 78) Position 1 = 71, Position 2 = 80
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 79
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 79
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
Branch analysis from position: 68
filename:       /in/kH7hD
function name:  __construct
number of ops:  82
compiled vars:  !0 = $args, !1 = $nameClass, !2 = $properties, !3 = $keys, !4 = $k, !5 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV_INIT                                        !0      <array>
   28     1        FETCH_THIS                                       ~6      
          2        GET_CLASS                                        ~7      ~6
          3        ASSIGN                                                   !1, ~7
   31     4        INIT_FCALL                                               'get_class_vars'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !2, $9
   32     8        INIT_FCALL                                               'array_keys'
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !3, $11
   33    12      > FE_RESET_R                                       $13     !3, ->68
         13    > > FE_FETCH_R                                               $13, !4, ->68
   34    14    >   INIT_FCALL                                               'method_exists'
         15        FETCH_THIS                                       ~14     
         16        SEND_VAL                                                 ~14
         17        INIT_FCALL                                               'ucfirst'
         18        SEND_VAR                                                 !4
         19        DO_ICALL                                         $15     
         20        CONCAT                                           ~16     'set', $15
         21        SEND_VAL                                                 ~16
         22        DO_ICALL                                         $17     
         23      > JMPNZ_EX                                         ~18     $17, ->34
         24    >   INIT_FCALL                                               'method_exists'
         25        FETCH_THIS                                       ~19     
         26        SEND_VAL                                                 ~19
         27        INIT_FCALL                                               'ucfirst'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $20     
         30        CONCAT                                           ~21     'get', $20
         31        SEND_VAL                                                 ~21
         32        DO_ICALL                                         $22     
         33        BOOL                                             ~18     $22
         34    > > JMPZ_EX                                          ~18     ~18, ->55
   35    35    >   INIT_FCALL                                               'method_exists'
         36        FETCH_THIS                                       ~23     
         37        SEND_VAL                                                 ~23
         38        INIT_FCALL                                               'ucfirst'
         39        SEND_VAR                                                 !4
         40        DO_ICALL                                         $24     
         41        CONCAT                                           ~25     'has', $24
         42      > JMPZ_EX                                          ~25     ~25, ->51
         43    >   INIT_FCALL                                               'ucfirst'
         44        SEND_VAR                                                 !4
         45        DO_ICALL                                         $27     
         46        CONCAT                                           ~28     'has', $27
         47        FETCH_OBJ_IS                                     ~26     'funcs'
         48        ISSET_ISEMPTY_DIM_OBJ                         0  ~29     ~26, ~28
         49        BOOL_NOT                                         ~30     ~29
         50        BOOL                                             ~25     ~30
         51    >   SEND_VAL                                                 ~25
         52        DO_ICALL                                         $31     
         53        BOOL_NOT                                         ~32     $31
         54        BOOL                                             ~18     ~32
         55    > > JMPZ                                                     ~18, ->67
   37    56    >   FETCH_OBJ_W                                      $33     !4
         57        ASSIGN_REF                                               !5, $33
   38    58        INIT_FCALL                                               'ucfirst'
         59        SEND_VAR                                                 !4
         60        DO_ICALL                                         $36     
         61        CONCAT                                           ~37     'has', $36
         62        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FkH7hD%3A38%240'
         63        BIND_LEXICAL                                             ~39, !5
         64        FETCH_OBJ_W                                      $35     'funcs'
         65        ASSIGN_DIM                                               $35, ~37
         66        OP_DATA                                                  ~39
   33    67    > > JMP                                                      ->13
         68    >   FE_FREE                                                  $13
   43    69      > FE_RESET_R                                       $40     !0, ->80
         70    > > FE_FETCH_R                                       ~41     $40, !5, ->80
         71    >   ASSIGN                                                   !4, ~41
   44    72        INIT_FCALL                                               'property_exists'
         73        SEND_VAR                                                 !1
         74        SEND_VAR                                                 !4
         75        DO_ICALL                                         $43     
         76      > JMPZ                                                     $43, ->79
   45    77    >   ASSIGN_OBJ                                               !4
         78        OP_DATA                                                  !5
   43    79    > > JMP                                                      ->70
         80    >   FE_FREE                                                  $40
   48    81      > RETURN                                                   null

End of function __construct

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.21 ms | 1424 KiB | 25 Q