3v4l.org

run code in 500+ PHP versions simultaneously
<?php abstract class Operation { public function __construct( protected ?string $name = null, protected ?string $foo = null, ) {} } class HttpOperation extends Operation { public function __construct( ?string $name = null, ?string $bar = null, protected string $method = 'GET', ) { $rc = new \ReflectionClass(self::class); $params = $rc->getMethod('__construct')->getParameters(); $paramsByName = []; foreach($params as $p) { $paramsByName[$p->getName()] = $p; } $a = []; foreach (func_get_args() as $i => $v) { $a[$params[$i]->getName()] = $v; } $args = []; $parentConstruct = $rc->getParentClass()->getMethod('__construct'); foreach ($parentConstruct->getParameters() as $parameter) { $args[$name = $parameter->getName()] = $a[$name] ?? null; if (null === $args[$name] && isset($paramsByName[$name]) && $paramsByName[$name]->isDefaultValueAvailable()) { $args[$name] = $paramsByName[$name]->getDefaultValue(); } } $parentConstruct->invokeArgs($this, $args); } } class Get extends HttpOperation { public function __construct( ?string $name = null, ?string $bar = null, string $method = 'GET', ) { $rc = new \ReflectionClass(self::class); $params = $rc->getMethod('__construct')->getParameters(); $paramsByName = []; foreach($params as $p) { $paramsByName[$p->getName()] = $p; } $a = []; foreach (func_get_args() as $i => $v) { $a[$params[$i]->getName()] = $v; } $args = []; $parentConstruct = $rc->getParentClass()->getMethod('__construct'); foreach ($parentConstruct->getParameters() as $parameter) { $args[$name = $parameter->getName()] = $a[$name] ?? null; if (null === $args[$name] && isset($paramsByName[$name]) && $paramsByName[$name]->isDefaultValueAvailable()) { $args[$name] = $paramsByName[$name]->getDefaultValue(); } } $parentConstruct->invokeArgs($this, $args); } } var_dump(new Get(name: 'test', method: 'POST')); var_dump(new Get(name: 'test'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h5FGN
function name:  (null)
number of ops:  16
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   86     0  E >   INIT_FCALL                                                   'var_dump'
          1        NEW                                                  $0      'Get'
          2        SEND_VAL_EX                                                  'test', 'name'
          3        SEND_VAL_EX                                                  'POST', 'method'
          4        CHECK_UNDEF_ARGS                                             
          5        DO_FCALL                                          1          
          6        SEND_VAR                                                     $0
          7        DO_ICALL                                                     
   87     8        INIT_FCALL                                                   'var_dump'
          9        NEW                                                  $3      'Get'
         10        SEND_VAL_EX                                                  'test', 'name'
         11        CHECK_UNDEF_ARGS                                             
         12        DO_FCALL                                          1          
         13        SEND_VAR                                                     $3
         14        DO_ICALL                                                     
         15      > RETURN                                                       1

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

End of function __construct

End of class Operation.

Class HttpOperation:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 35
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 35
2 jumps found. (Code = 77) Position 1 = 46, Position 2 = 72
Branch analysis from position: 46
2 jumps found. (Code = 78) Position 1 = 47, Position 2 = 72
Branch analysis from position: 47
2 jumps found. (Code = 46) Position 1 = 58, Position 2 = 60
Branch analysis from position: 58
2 jumps found. (Code = 46) Position 1 = 61, Position 2 = 65
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 71
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 71
Branch analysis from position: 65
Branch analysis from position: 60
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
Branch analysis from position: 35
Branch analysis from position: 23
filename:       /in/h5FGN
function name:  __construct
number of ops:  79
compiled vars:  !0 = $name, !1 = $bar, !2 = $method, !3 = $rc, !4 = $params, !5 = $paramsByName, !6 = $p, !7 = $a, !8 = $v, !9 = $i, !10 = $args, !11 = $parentConstruct, !12 = $parameter
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV_INIT                                            !0      null
   15     1        RECV_INIT                                            !1      null
   16     2        RECV_INIT                                            !2      'GET'
          3        ASSIGN_OBJ                                                   'method'
          4        OP_DATA                                                      !2
   18     5        NEW                                                  $13     'ReflectionClass'
          6        SEND_VAL_EX                                                  'HttpOperation'
          7        DO_FCALL                                          0          
          8        ASSIGN                                                       !3, $13
   19     9        INIT_METHOD_CALL                                             !3, 'getMethod'
         10        SEND_VAL_EX                                                  '__construct'
         11        DO_FCALL                                          0  $16     
         12        INIT_METHOD_CALL                                             $16, 'getParameters'
         13        DO_FCALL                                          0  $17     
         14        ASSIGN                                                       !4, $17
   20    15        ASSIGN                                                       !5, <array>
   22    16      > FE_RESET_R                                           $20     !4, ->23
         17    > > FE_FETCH_R                                                   $20, !6, ->23
   23    18    >   INIT_METHOD_CALL                                             !6, 'getName'
         19        DO_FCALL                                          0  $21     
         20        ASSIGN_DIM                                                   !5, $21
         21        OP_DATA                                                      !6
   22    22      > JMP                                                          ->17
         23    >   FE_FREE                                                      $20
   26    24        ASSIGN                                                       !7, <array>
   28    25        FUNC_GET_ARGS                                        ~24     
         26      > FE_RESET_R                                           $25     ~24, ->35
         27    > > FE_FETCH_R                                           ~26     $25, !8, ->35
         28    >   ASSIGN                                                       !9, ~26
   29    29        FETCH_DIM_R                                          ~28     !4, !9
         30        INIT_METHOD_CALL                                             ~28, 'getName'
         31        DO_FCALL                                          0  $29     
         32        ASSIGN_DIM                                                   !7, $29
         33        OP_DATA                                                      !8
   28    34      > JMP                                                          ->27
         35    >   FE_FREE                                                      $25
   32    36        ASSIGN                                                       !10, <array>
   34    37        INIT_METHOD_CALL                                             !3, 'getParentClass'
         38        DO_FCALL                                          0  $32     
         39        INIT_METHOD_CALL                                             $32, 'getMethod'
         40        SEND_VAL_EX                                                  '__construct'
         41        DO_FCALL                                          0  $33     
         42        ASSIGN                                                       !11, $33
   35    43        INIT_METHOD_CALL                                             !11, 'getParameters'
         44        DO_FCALL                                          0  $35     
         45      > FE_RESET_R                                           $36     $35, ->72
         46    > > FE_FETCH_R                                                   $36, !12, ->72
   36    47    >   INIT_METHOD_CALL                                             !12, 'getName'
         48        DO_FCALL                                          0  $37     
         49        ASSIGN                                               ~38     !0, $37
         50        FETCH_DIM_IS                                         ~40     !7, !0
         51        COALESCE                                             ~41     ~40
         52        QM_ASSIGN                                            ~41     null
         53        ASSIGN_DIM                                                   !10, ~38
         54        OP_DATA                                                      ~41
   38    55        FETCH_DIM_R                                          ~42     !10, !0
         56        TYPE_CHECK                                        2  ~43     ~42
         57      > JMPZ_EX                                              ~43     ~43, ->60
         58    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~44     !5, !0
         59        BOOL                                                 ~43     ~44
         60    > > JMPZ_EX                                              ~43     ~43, ->65
         61    >   FETCH_DIM_R                                          ~45     !5, !0
         62        INIT_METHOD_CALL                                             ~45, 'isDefaultValueAvailable'
         63        DO_FCALL                                          0  $46     
         64        BOOL                                                 ~43     $46
         65    > > JMPZ                                                         ~43, ->71
   39    66    >   FETCH_DIM_R                                          ~48     !5, !0
         67        INIT_METHOD_CALL                                             ~48, 'getDefaultValue'
         68        DO_FCALL                                          0  $49     
         69        ASSIGN_DIM                                                   !10, !0
         70        OP_DATA                                                      $49
   35    71    > > JMP                                                          ->46
         72    >   FE_FREE                                                      $36
   43    73        INIT_METHOD_CALL                                             !11, 'invokeArgs'
         74        FETCH_THIS                                           $50     
         75        SEND_VAR_EX                                                  $50
         76        SEND_VAR_EX                                                  !10
         77        DO_FCALL                                          0          
   45    78      > RETURN                                                       null

End of function __construct

End of class HttpOperation.

Class Get:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 33
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 70
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 70
Branch analysis from position: 45
2 jumps found. (Code = 46) Position 1 = 56, Position 2 = 58
Branch analysis from position: 56
2 jumps found. (Code = 46) Position 1 = 59, Position 2 = 63
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 69
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 69
Branch analysis from position: 63
Branch analysis from position: 58
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
Branch analysis from position: 33
Branch analysis from position: 21
filename:       /in/h5FGN
function name:  __construct
number of ops:  77
compiled vars:  !0 = $name, !1 = $bar, !2 = $method, !3 = $rc, !4 = $params, !5 = $paramsByName, !6 = $p, !7 = $a, !8 = $v, !9 = $i, !10 = $args, !11 = $parentConstruct, !12 = $parameter
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   51     0  E >   RECV_INIT                                            !0      null
   52     1        RECV_INIT                                            !1      null
   53     2        RECV_INIT                                            !2      'GET'
   55     3        NEW                                                  $13     'ReflectionClass'
          4        SEND_VAL_EX                                                  'Get'
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !3, $13
   56     7        INIT_METHOD_CALL                                             !3, 'getMethod'
          8        SEND_VAL_EX                                                  '__construct'
          9        DO_FCALL                                          0  $16     
         10        INIT_METHOD_CALL                                             $16, 'getParameters'
         11        DO_FCALL                                          0  $17     
         12        ASSIGN                                                       !4, $17
   57    13        ASSIGN                                                       !5, <array>
   59    14      > FE_RESET_R                                           $20     !4, ->21
         15    > > FE_FETCH_R                                                   $20, !6, ->21
   60    16    >   INIT_METHOD_CALL                                             !6, 'getName'
         17        DO_FCALL                                          0  $21     
         18        ASSIGN_DIM                                                   !5, $21
         19        OP_DATA                                                      !6
   59    20      > JMP                                                          ->15
         21    >   FE_FREE                                                      $20
   63    22        ASSIGN                                                       !7, <array>
   65    23        FUNC_GET_ARGS                                        ~24     
         24      > FE_RESET_R                                           $25     ~24, ->33
         25    > > FE_FETCH_R                                           ~26     $25, !8, ->33
         26    >   ASSIGN                                                       !9, ~26
   66    27        FETCH_DIM_R                                          ~28     !4, !9
         28        INIT_METHOD_CALL                                             ~28, 'getName'
         29        DO_FCALL                                          0  $29     
         30        ASSIGN_DIM                                                   !7, $29
         31        OP_DATA                                                      !8
   65    32      > JMP                                                          ->25
         33    >   FE_FREE                                                      $25
   69    34        ASSIGN                                                       !10, <array>
   71    35        INIT_METHOD_CALL                                             !3, 'getParentClass'
         36        DO_FCALL                                          0  $32     
         37        INIT_METHOD_CALL                                             $32, 'getMethod'
         38        SEND_VAL_EX                                                  '__construct'
         39        DO_FCALL                                          0  $33     
         40        ASSIGN                                                       !11, $33
   72    41        INIT_METHOD_CALL                                             !11, 'getParameters'
         42        DO_FCALL                                          0  $35     
         43      > FE_RESET_R                                           $36     $35, ->70
         44    > > FE_FETCH_R                                                   $36, !12, ->70
   73    45    >   INIT_METHOD_CALL                                             !12, 'getName'
         46        DO_FCALL                                          0  $37     
         47        ASSIGN                                               ~38     !0, $37
         48        FETCH_DIM_IS                                         ~40     !7, !0
         49        COALESCE                                             ~41     ~40
         50        QM_ASSIGN                                            ~41     null
         51        ASSIGN_DIM                                                   !10, ~38
         52        OP_DATA                                                      ~41
   75    53        FETCH_DIM_R                                          ~42     !10, !0
         54        TYPE_CHECK                                        2  ~43     ~42
         55      > JMPZ_EX                                              ~43     ~43, ->58
         56    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~44     !5, !0
         57        BOOL                                                 ~43     ~44
         58    > > JMPZ_EX                                              ~43     ~43, ->63
         59    >   FETCH_DIM_R                                          ~45     !5, !0
         60        INIT_METHOD_CALL                                             ~45, 'isDefaultValueAvailable'
         61        DO_FCALL                                          0  $46     
         62        BOOL                                                 ~43     $46
         63    > > JMPZ                                                         ~43, ->69
   76    64    >   FETCH_DIM_R                                          ~48     !5, !0
         65        INIT_METHOD_CALL                                             ~48, 'getDefaultValue'
         66        DO_FCALL                                          0  $49     
         67        ASSIGN_DIM                                                   !10, !0
         68        OP_DATA                                                      $49
   72    69    > > JMP                                                          ->44
         70    >   FE_FREE                                                      $36
   80    71        INIT_METHOD_CALL                                             !11, 'invokeArgs'
         72        FETCH_THIS                                           $50     
         73        SEND_VAR_EX                                                  $50
         74        SEND_VAR_EX                                                  !10
         75        DO_FCALL                                          0          
   82    76      > RETURN                                                       null

End of function __construct

End of class Get.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
127.74 ms | 498 KiB | 8 Q