3v4l.org

run code in 500+ PHP versions simultaneously
<?php class MyEntity { public ?int $id = null; public ?\DateTimeImmutable $updatedAt = null; public function setUpdatedAt(): self { if (null !== $this->id || null === $this->updatedAt) { $this->updatedAt = new DateTimeImmutable(); } return $this; } } // Insert without custom date $a = new MyEntity(); $a->setUpdatedAt(); var_dump($a); // Insert with custom date $b = new MyEntity(); $b->updatedAt = new \DateTimeImmutable('2022-09-16'); $b->setUpdatedAt(); var_dump($b); // Update $c = new MyEntity(); $c->id = 42; $c->updatedAt = new \DateTimeImmutable('2022-09-16'); $c->setUpdatedAt(); var_dump($c);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F9dVj
function name:  (null)
number of ops:  37
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   NEW                                                  $3      'MyEntity'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $3
   20     3        INIT_METHOD_CALL                                             !0, 'setUpdatedAt'
          4        DO_FCALL                                          0          
   21     5        INIT_FCALL                                                   'var_dump'
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                                     
   24     8        NEW                                                  $8      'MyEntity'
          9        DO_FCALL                                          0          
         10        ASSIGN                                                       !1, $8
   25    11        NEW                                                  $12     'DateTimeImmutable'
         12        SEND_VAL_EX                                                  '2022-09-16'
         13        DO_FCALL                                          0          
         14        ASSIGN_OBJ                                                   !1, 'updatedAt'
         15        OP_DATA                                                      $12
   26    16        INIT_METHOD_CALL                                             !1, 'setUpdatedAt'
         17        DO_FCALL                                          0          
   27    18        INIT_FCALL                                                   'var_dump'
         19        SEND_VAR                                                     !1
         20        DO_ICALL                                                     
   30    21        NEW                                                  $16     'MyEntity'
         22        DO_FCALL                                          0          
         23        ASSIGN                                                       !2, $16
   31    24        ASSIGN_OBJ                                                   !2, 'id'
         25        OP_DATA                                                      42
   32    26        NEW                                                  $21     'DateTimeImmutable'
         27        SEND_VAL_EX                                                  '2022-09-16'
         28        DO_FCALL                                          0          
         29        ASSIGN_OBJ                                                   !2, 'updatedAt'
         30        OP_DATA                                                      $21
   33    31        INIT_METHOD_CALL                                             !2, 'setUpdatedAt'
         32        DO_FCALL                                          0          
   34    33        INIT_FCALL                                                   'var_dump'
         34        SEND_VAR                                                     !2
         35        DO_ICALL                                                     
         36      > RETURN                                                       1

Class MyEntity:
Function setupdatedat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
Branch analysis from position: 6
filename:       /in/F9dVj
function name:  setUpdatedAt
number of ops:  16
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   FETCH_OBJ_R                                          ~0      'id'
          1        TYPE_CHECK                                      1020  ~1      ~0
          2      > JMPNZ_EX                                             ~1      ~1, ->6
          3    >   FETCH_OBJ_R                                          ~2      'updatedAt'
          4        TYPE_CHECK                                        2  ~3      ~2
          5        BOOL                                                 ~1      ~3
          6    > > JMPZ                                                         ~1, ->11
   11     7    >   NEW                                                  $5      'DateTimeImmutable'
          8        DO_FCALL                                          0          
          9        ASSIGN_OBJ                                                   'updatedAt'
         10        OP_DATA                                                      $5
   14    11    >   FETCH_THIS                                           ~7      
         12        VERIFY_RETURN_TYPE                                           ~7
         13      > RETURN                                                       ~7
   15    14*       VERIFY_RETURN_TYPE                                           
         15*     > RETURN                                                       null

End of function setupdatedat

End of class MyEntity.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.74 ms | 1852 KiB | 14 Q