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"); $dtWithout = $dtWith; $invert = true; for ($i = 0; $i < 3; $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 < 3; $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 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 13
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 50
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 50
Branch analysis from position: 77
Branch analysis from position: 50
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 13
Branch analysis from position: 40
Branch analysis from position: 13
filename:       /in/hGXcr
function name:  (null)
number of ops:  78
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        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !1, $8
   23     9        ASSIGN                                                   !2, !1
   25    10        ASSIGN                                                   !3, <true>
   26    11        ASSIGN                                                   !4, 0
         12      > JMP                                                      ->38
   27    13    >   ROPE_INIT                                     3  ~14     '%0ARound+'
         14        ROPE_ADD                                      1  ~14     ~14, !4
         15        ROPE_END                                      2  ~13     ~14, '%3A'
         16        ECHO                                                     ~13
   28    17        INIT_FCALL                                               'incrementwithswitch'
         18        SEND_VAR                                                 !1
         19        SEND_VAR                                                 !3
         20        DO_FCALL                                      0  $16     
         21        ASSIGN                                                   !1, $16
   29    22        INIT_FCALL                                               'incrementwithoutswitch'
         23        SEND_VAR                                                 !2
         24        SEND_VAR                                                 !3
         25        DO_FCALL                                      0  $18     
         26        ASSIGN                                                   !2, $18
   30    27        INIT_METHOD_CALL                                         !1, 'format'
         28        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         29        DO_FCALL                                      0  $20     
         30        CONCAT                                           ~21     'With+switch%3A++++', $20
         31        ECHO                                                     ~21
   31    32        INIT_METHOD_CALL                                         !2, 'format'
         33        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         34        DO_FCALL                                      0  $22     
         35        CONCAT                                           ~23     '+%3A%3A+Without+switch%3A+', $22
         36        ECHO                                                     ~23
   26    37        PRE_INC                                                  !4
         38    >   IS_SMALLER                                               !4, 3
         39      > JMPNZ                                                    ~25, ->13
   34    40    >   ECHO                                                     '%0A---%0A'
   36    41        INIT_STATIC_METHOD_CALL                                  'DateTimeImmutable', 'createFromFormat'
         42        SEND_VAL                                                 '%21Y-m-d+H%3Ai%3As'
         43        SEND_VAL                                                 '2021-03-28+00%3A00%3A00'
         44        DO_FCALL                                      0  $26     
         45        ASSIGN                                                   !1, $26
   37    46        ASSIGN                                                   !2, !1
   39    47        ASSIGN                                                   !3, <false>
   40    48        ASSIGN                                                   !4, 0
         49      > JMP                                                      ->75
   41    50    >   ROPE_INIT                                     3  ~32     '%0ARound+'
         51        ROPE_ADD                                      1  ~32     ~32, !4
         52        ROPE_END                                      2  ~31     ~32, '%3A'
         53        ECHO                                                     ~31
   42    54        INIT_FCALL                                               'incrementwithswitch'
         55        SEND_VAR                                                 !1
         56        SEND_VAR                                                 !3
         57        DO_FCALL                                      0  $34     
         58        ASSIGN                                                   !1, $34
   43    59        INIT_FCALL                                               'incrementwithoutswitch'
         60        SEND_VAR                                                 !2
         61        SEND_VAR                                                 !3
         62        DO_FCALL                                      0  $36     
         63        ASSIGN                                                   !2, $36
   44    64        INIT_METHOD_CALL                                         !1, 'format'
         65        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         66        DO_FCALL                                      0  $38     
         67        CONCAT                                           ~39     'With+switch%3A++++', $38
         68        ECHO                                                     ~39
   45    69        INIT_METHOD_CALL                                         !2, 'format'
         70        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         71        DO_FCALL                                      0  $40     
         72        CONCAT                                           ~41     '+%3A%3A+Without+switch%3A+', $40
         73        ECHO                                                     ~41
   40    74        PRE_INC                                                  !4
         75    >   IS_SMALLER                                               !4, 3
         76      > JMPNZ                                                    ~43, ->50
   46    77    > > 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/hGXcr
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/hGXcr
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:
208.1 ms | 1411 KiB | 17 Q