3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isWeekend($date) { if ($date instanceof DateTime) { $date = DateTimeImmutable::createFromMutable($date); } return $date->setTime(0,0,0) != $date->modify('this weekday'); } function isWeekendUnixTimestamp($dateValue) { return date('Yz', strtotime($dateValue)) != date('Yz', strtotime($dateValue . ' this weekday')); } echo 'DateTimeInterface Comparison:' . PHP_EOL; $sunday = new DateTimeImmutable('Sunday'); $periods = new DatePeriod($sunday, new DateInterval('P1D'), 6); foreach ($periods as $date) { echo $date->format('D') . ' is' . (isWeekend($date) ? '' : ' not') . ' a weekend' . PHP_EOL; } echo PHP_EOL . 'String Comparison:' . PHP_EOL; foreach ($periods as $date) { echo $date->format('D') . ' is' . (isWeekendUnixTimestamp($date->format('Y-m-d')) ? '' : ' not') . ' a weekend' . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 32
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 32
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 55
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 55
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
Branch analysis from position: 32
filename:       /in/TSAVi
function name:  (null)
number of ops:  57
compiled vars:  !0 = $sunday, !1 = $periods, !2 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ECHO                                                     'DateTimeInterface+Comparison%3A%0A'
   19     1        NEW                                              $3      'DateTimeImmutable'
          2        SEND_VAL_EX                                              'Sunday'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   20     5        NEW                                              $6      'DatePeriod'
          6        SEND_VAR_EX                                              !0
          7        NEW                                              $7      'DateInterval'
          8        SEND_VAL_EX                                              'P1D'
          9        DO_FCALL                                      0          
         10        SEND_VAR_NO_REF_EX                                       $7
         11        SEND_VAL_EX                                              6
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !1, $6
   21    14      > FE_RESET_R                                       $11     !1, ->32
         15    > > FE_FETCH_R                                               $11, !2, ->32
   22    16    >   INIT_METHOD_CALL                                         !2, 'format'
         17        SEND_VAL_EX                                              'D'
         18        DO_FCALL                                      0  $12     
         19        CONCAT                                           ~13     $12, '+is'
         20        INIT_FCALL                                               'isweekend'
         21        SEND_VAR                                                 !2
         22        DO_FCALL                                      0  $14     
         23      > JMPZ                                                     $14, ->26
         24    >   QM_ASSIGN                                        ~15     ''
         25      > JMP                                                      ->27
         26    >   QM_ASSIGN                                        ~15     '+not'
         27    >   CONCAT                                           ~16     ~13, ~15
         28        CONCAT                                           ~17     ~16, '+a+weekend'
         29        CONCAT                                           ~18     ~17, '%0A'
         30        ECHO                                                     ~18
   21    31      > JMP                                                      ->15
         32    >   FE_FREE                                                  $11
   25    33        ECHO                                                     '%0AString+Comparison%3A%0A'
   26    34      > FE_RESET_R                                       $19     !1, ->55
         35    > > FE_FETCH_R                                               $19, !2, ->55
   27    36    >   INIT_METHOD_CALL                                         !2, 'format'
         37        SEND_VAL_EX                                              'D'
         38        DO_FCALL                                      0  $20     
         39        CONCAT                                           ~21     $20, '+is'
         40        INIT_FCALL                                               'isweekendunixtimestamp'
         41        INIT_METHOD_CALL                                         !2, 'format'
         42        SEND_VAL_EX                                              'Y-m-d'
         43        DO_FCALL                                      0  $22     
         44        SEND_VAR                                                 $22
         45        DO_FCALL                                      0  $23     
         46      > JMPZ                                                     $23, ->49
         47    >   QM_ASSIGN                                        ~24     ''
         48      > JMP                                                      ->50
         49    >   QM_ASSIGN                                        ~24     '+not'
         50    >   CONCAT                                           ~25     ~21, ~24
         51        CONCAT                                           ~26     ~25, '+a+weekend'
         52        CONCAT                                           ~27     ~26, '%0A'
         53        ECHO                                                     ~27
   26    54      > JMP                                                      ->35
         55    >   FE_FREE                                                  $19
   28    56      > RETURN                                                   1

Function isweekend:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/TSAVi
function name:  isWeekend
number of ops:  18
compiled vars:  !0 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INSTANCEOF                                               !0, 'DateTime'
          2      > JMPZ                                                     ~1, ->7
    6     3    >   INIT_STATIC_METHOD_CALL                                  'DateTimeImmutable', 'createFromMutable'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6        ASSIGN                                                   !0, $2
    9     7    >   INIT_METHOD_CALL                                         !0, 'setTime'
          8        SEND_VAL_EX                                              0
          9        SEND_VAL_EX                                              0
         10        SEND_VAL_EX                                              0
         11        DO_FCALL                                      0  $4      
         12        INIT_METHOD_CALL                                         !0, 'modify'
         13        SEND_VAL_EX                                              'this+weekday'
         14        DO_FCALL                                      0  $5      
         15        IS_NOT_EQUAL                                     ~6      $4, $5
         16      > RETURN                                                   ~6
   10    17*     > RETURN                                                   null

End of function isweekend

Function isweekendunixtimestamp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TSAVi
function name:  isWeekendUnixTimestamp
number of ops:  19
compiled vars:  !0 = $dateValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        INIT_FCALL                                               'date'
          2        SEND_VAL                                                 'Yz'
          3        INIT_FCALL                                               'strtotime'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
          7        DO_ICALL                                         $2      
          8        INIT_FCALL                                               'date'
          9        SEND_VAL                                                 'Yz'
         10        INIT_FCALL                                               'strtotime'
         11        CONCAT                                           ~3      !0, '+this+weekday'
         12        SEND_VAL                                                 ~3
         13        DO_ICALL                                         $4      
         14        SEND_VAR                                                 $4
         15        DO_ICALL                                         $5      
         16        IS_NOT_EQUAL                                     ~6      $2, $5
         17      > RETURN                                                   ~6
   15    18*     > RETURN                                                   null

End of function isweekendunixtimestamp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.7 ms | 1407 KiB | 19 Q