3v4l.org

run code in 300+ PHP versions simultaneously
<?php function incrementWithSwitch($date, $invert) { $timezone = $date->getTimezone(); $date = $date->setTimezone(new DateTimeZone('UTC')); $date = $date->modify(($invert ? '-' : '+') . '1 hour'); $date = $date->setTimezone($timezone); $date = $date->setTime((int)$date->format('H'), 0); return $date; } function incrementWithoutSwitch($date, $invert) { $date = $date->modify(($invert ? '-' : '+') . '1 hour'); return $date; } $tz = new \DateTimeZone("Europe/London"); $dtWith = \DateTimeImmutable::createFromFormat("!Y-m-d H:i:s", "2021-03-28 04:00:00", $tz); $dtWithout = $dtWith; $invert = true; for ($i = 0; $i < 4; $i++) { print "\nRound {$i}:"; $dtWith = incrementWithSwitch($dtWith, $invert); $dtWithout = incrementWithoutSwitch($dtWithout, $invert); print "With switch: ". $dtWith->format(\DateTime::RFC3339); print " :: Without switch: ". $dtWithout->format(\DateTime::RFC3339); } print "\n---\n"; $dtWith = \DateTimeImmutable::createFromFormat("!Y-m-d H:i:s", "2021-03-28 00:00:00"); $dtWithout = $dtWith; $invert = false; for ($i = 0; $i < 4; $i++) { print "\nRound {$i}:"; $dtWith = incrementWithSwitch($dtWith, $invert); $dtWithout = incrementWithoutSwitch($dtWithout, $invert); print "With switch: ". $dtWith->format(\DateTime::RFC3339); print " :: Without switch: ". $dtWithout->format(\DateTime::RFC3339); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 14
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
2 jumps found. (Code = 44) Position 1 = 78, Position 2 = 51
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 78, Position 2 = 51
Branch analysis from position: 78
Branch analysis from position: 51
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 14
Branch analysis from position: 41
Branch analysis from position: 14
filename:       /in/01oD9
function name:  (null)
number of ops:  79
compiled vars:  !0 = $tz, !1 = $dtWith, !2 = $dtWithout, !3 = $invert, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   NEW                                              $5      'DateTimeZone'
          1        SEND_VAL_EX                                              'Europe%2FLondon'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $5
   22     4        INIT_STATIC_METHOD_CALL                                  'DateTimeImmutable', 'createFromFormat'
          5        SEND_VAL                                                 '%21Y-m-d+H%3Ai%3As'
          6        SEND_VAL                                                 '2021-03-28+04%3A00%3A00'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !1, $8
   23    10        ASSIGN                                                   !2, !1
   25    11        ASSIGN                                                   !3, <true>
   26    12        ASSIGN                                                   !4, 0
         13      > JMP                                                      ->39
   27    14    >   ROPE_INIT                                     3  ~14     '%0ARound+'
         15        ROPE_ADD                                      1  ~14     ~14, !4
         16        ROPE_END                                      2  ~13     ~14, '%3A'
         17        ECHO                                                     ~13
   28    18        INIT_FCALL                                               'incrementwithswitch'
         19        SEND_VAR                                                 !1
         20        SEND_VAR                                                 !3
         21        DO_FCALL                                      0  $16     
         22        ASSIGN                                                   !1, $16
   29    23        INIT_FCALL                                               'incrementwithoutswitch'
         24        SEND_VAR                                                 !2
         25        SEND_VAR                                                 !3
         26        DO_FCALL                                      0  $18     
         27        ASSIGN                                                   !2, $18
   30    28        INIT_METHOD_CALL                                         !1, 'format'
         29        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         30        DO_FCALL                                      0  $20     
         31        CONCAT                                           ~21     'With+switch%3A++++', $20
         32        ECHO                                                     ~21
   31    33        INIT_METHOD_CALL                                         !2, 'format'
         34        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         35        DO_FCALL                                      0  $22     
         36        CONCAT                                           ~23     '+%3A%3A+Without+switch%3A+', $22
         37        ECHO                                                     ~23
   26    38        PRE_INC                                                  !4
         39    >   IS_SMALLER                                               !4, 4
         40      > JMPNZ                                                    ~25, ->14
   34    41    >   ECHO                                                     '%0A---%0A'
   36    42        INIT_STATIC_METHOD_CALL                                  'DateTimeImmutable', 'createFromFormat'
         43        SEND_VAL                                                 '%21Y-m-d+H%3Ai%3As'
         44        SEND_VAL                                                 '2021-03-28+00%3A00%3A00'
         45        DO_FCALL                                      0  $26     
         46        ASSIGN                                                   !1, $26
   37    47        ASSIGN                                                   !2, !1
   39    48        ASSIGN                                                   !3, <false>
   40    49        ASSIGN                                                   !4, 0
         50      > JMP                                                      ->76
   41    51    >   ROPE_INIT                                     3  ~32     '%0ARound+'
         52        ROPE_ADD                                      1  ~32     ~32, !4
         53        ROPE_END                                      2  ~31     ~32, '%3A'
         54        ECHO                                                     ~31
   42    55        INIT_FCALL                                               'incrementwithswitch'
         56        SEND_VAR                                                 !1
         57        SEND_VAR                                                 !3
         58        DO_FCALL                                      0  $34     
         59        ASSIGN                                                   !1, $34
   43    60        INIT_FCALL                                               'incrementwithoutswitch'
         61        SEND_VAR                                                 !2
         62        SEND_VAR                                                 !3
         63        DO_FCALL                                      0  $36     
         64        ASSIGN                                                   !2, $36
   44    65        INIT_METHOD_CALL                                         !1, 'format'
         66        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         67        DO_FCALL                                      0  $38     
         68        CONCAT                                           ~39     'With+switch%3A++++', $38
         69        ECHO                                                     ~39
   45    70        INIT_METHOD_CALL                                         !2, 'format'
         71        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         72        DO_FCALL                                      0  $40     
         73        CONCAT                                           ~41     '+%3A%3A+Without+switch%3A+', $40
         74        ECHO                                                     ~41
   40    75        PRE_INC                                                  !4
         76    >   IS_SMALLER                                               !4, 4
         77      > JMPNZ                                                    ~43, ->51
   46    78    > > RETURN                                                   1

Function incrementwithswitch:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/01oD9
function name:  incrementWithSwitch
number of ops:  36
compiled vars:  !0 = $date, !1 = $invert, !2 = $timezone
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_METHOD_CALL                                         !0, 'getTimezone'
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !2, $3
    6     5        INIT_METHOD_CALL                                         !0, 'setTimezone'
          6        NEW                                              $5      'DateTimeZone'
          7        SEND_VAL_EX                                              'UTC'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $5
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !0, $7
    7    12        INIT_METHOD_CALL                                         !0, 'modify'
         13      > JMPZ                                                     !1, ->16
         14    >   QM_ASSIGN                                        ~9      '-'
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~9      '%2B'
         17    >   CONCAT                                           ~10     ~9, '1+hour'
         18        SEND_VAL_EX                                              ~10
         19        DO_FCALL                                      0  $11     
         20        ASSIGN                                                   !0, $11
    8    21        INIT_METHOD_CALL                                         !0, 'setTimezone'
         22        SEND_VAR_EX                                              !2
         23        DO_FCALL                                      0  $13     
         24        ASSIGN                                                   !0, $13
   10    25        INIT_METHOD_CALL                                         !0, 'setTime'
         26        INIT_METHOD_CALL                                         !0, 'format'
         27        SEND_VAL_EX                                              'H'
         28        DO_FCALL                                      0  $15     
         29        CAST                                          4  ~16     $15
         30        SEND_VAL_EX                                              ~16
         31        SEND_VAL_EX                                              0
         32        DO_FCALL                                      0  $17     
         33        ASSIGN                                                   !0, $17
   11    34      > RETURN                                                   !0
   12    35*     > RETURN                                                   null

End of function incrementwithswitch

Function incrementwithoutswitch:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/01oD9
function name:  incrementWithoutSwitch
number of ops:  13
compiled vars:  !0 = $date, !1 = $invert
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        INIT_METHOD_CALL                                         !0, 'modify'
          3      > JMPZ                                                     !1, ->6
          4    >   QM_ASSIGN                                        ~2      '-'
          5      > JMP                                                      ->7
          6    >   QM_ASSIGN                                        ~2      '%2B'
          7    >   CONCAT                                           ~3      ~2, '1+hour'
          8        SEND_VAL_EX                                              ~3
          9        DO_FCALL                                      0  $4      
         10        ASSIGN                                                   !0, $4
   18    11      > RETURN                                                   !0
   19    12*     > RETURN                                                   null

End of function incrementwithoutswitch

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.43 ms | 1415 KiB | 17 Q