3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyRequest { public function __construct() { $reflectedProperties = (new \ReflectionClass($this))->getProperties(); foreach ($reflectedProperties as $property) { !$property->isInitialized($this) && $property->getType()->allowsNull() ? $property->setValue($this, null) : null; } } } class PostRequest extends MyRequest { public ?string $title; public string $name; } $postRequest = new PostRequest(); $postRequest->name = 'foo'; // works fine - I have access here! foreach($postRequest as $property) { var_dump($property); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/LKikT
function name:  (null)
number of ops:  13
compiled vars:  !0 = $postRequest, !1 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   NEW                                              $2      'PostRequest'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   25     3        ASSIGN_OBJ                                               !0, 'name'
          4        OP_DATA                                                  'foo'
   28     5      > FE_RESET_R                                       $6      !0, ->11
          6    > > FE_FETCH_R                                               $6, !1, ->11
   29     7    >   INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   28    10      > JMP                                                      ->6
         11    >   FE_FREE                                                  $6
   30    12      > RETURN                                                   1

Class MyRequest:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 31
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 31
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 28
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 20
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/LKikT
function name:  __construct
number of ops:  33
compiled vars:  !0 = $reflectedProperties, !1 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   NEW                                              $2      'ReflectionClass'
          1        FETCH_THIS                                       $3      
          2        SEND_VAR_EX                                              $3
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $2, 'getProperties'
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !0, $5
    8     7      > FE_RESET_R                                       $7      !0, ->31
          8    > > FE_FETCH_R                                               $7, !1, ->31
    9     9    >   INIT_METHOD_CALL                                         !1, 'isInitialized'
         10        FETCH_THIS                                       $8      
         11        SEND_VAR_EX                                              $8
         12        DO_FCALL                                      0  $9      
         13        BOOL_NOT                                         ~10     $9
         14      > JMPZ_EX                                          ~10     ~10, ->20
   10    15    >   INIT_METHOD_CALL                                         !1, 'getType'
         16        DO_FCALL                                      0  $11     
         17        INIT_METHOD_CALL                                         $11, 'allowsNull'
         18        DO_FCALL                                      0  $12     
         19        BOOL                                             ~10     $12
         20    > > JMPZ                                                     ~10, ->28
         21    >   INIT_METHOD_CALL                                         !1, 'setValue'
         22        FETCH_THIS                                       $13     
         23        SEND_VAR_EX                                              $13
         24        SEND_VAL_EX                                              null
         25        DO_FCALL                                      0  $14     
         26        QM_ASSIGN                                        ~15     $14
         27      > JMP                                                      ->29
         28    >   QM_ASSIGN                                        ~15     null
         29    >   FREE                                                     ~15
    8    30      > JMP                                                      ->8
         31    >   FE_FREE                                                  $7
   12    32      > RETURN                                                   null

End of function __construct

End of class MyRequest.

Class PostRequest:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 31
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 31
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 28
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 20
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/LKikT
function name:  __construct
number of ops:  33
compiled vars:  !0 = $reflectedProperties, !1 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   NEW                                              $2      'ReflectionClass'
          1        FETCH_THIS                                       $3      
          2        SEND_VAR_EX                                              $3
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $2, 'getProperties'
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !0, $5
    8     7      > FE_RESET_R                                       $7      !0, ->31
          8    > > FE_FETCH_R                                               $7, !1, ->31
    9     9    >   INIT_METHOD_CALL                                         !1, 'isInitialized'
         10        FETCH_THIS                                       $8      
         11        SEND_VAR_EX                                              $8
         12        DO_FCALL                                      0  $9      
         13        BOOL_NOT                                         ~10     $9
         14      > JMPZ_EX                                          ~10     ~10, ->20
   10    15    >   INIT_METHOD_CALL                                         !1, 'getType'
         16        DO_FCALL                                      0  $11     
         17        INIT_METHOD_CALL                                         $11, 'allowsNull'
         18        DO_FCALL                                      0  $12     
         19        BOOL                                             ~10     $12
         20    > > JMPZ                                                     ~10, ->28
         21    >   INIT_METHOD_CALL                                         !1, 'setValue'
         22        FETCH_THIS                                       $13     
         23        SEND_VAR_EX                                              $13
         24        SEND_VAL_EX                                              null
         25        DO_FCALL                                      0  $14     
         26        QM_ASSIGN                                        ~15     $14
         27      > JMP                                                      ->29
         28    >   QM_ASSIGN                                        ~15     null
         29    >   FREE                                                     ~15
    8    30      > JMP                                                      ->8
         31    >   FE_FREE                                                  $7
   12    32      > RETURN                                                   null

End of function __construct

End of class PostRequest.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.33 ms | 1009 KiB | 14 Q