3v4l.org

run code in 500+ PHP versions simultaneously
<?php $tests = [ '2016-01','2016-02','2016-03','2016-04','2016-05','2016-06','2016-07','2016-08','2016-09','2016-10','2016-11','2016-12', '2018-01','2018-02','2018-03','2018-04','2018-05','2018-06','2018-07','2018-08','2018-09','2018-10','2018-11','2018-12', ]; foreach($tests as $test) { $start = new DateTime($test); $end = intval((clone $start)->modify('last day of this month')->format('W')); if($end < 2) $end = intval((clone $start)->modify('last sunday of this month')->format('W')) + 1; $start = intval($start->format('W')); if($start > 51) $start = 0;$weeks = $end - $start + 1; echo "$test = $weeks\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 45
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 45
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 28
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 36
Branch analysis from position: 28
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/WoAiN
function name:  (null)
number of ops:  47
compiled vars:  !0 = $tests, !1 = $test, !2 = $start, !3 = $end, !4 = $weeks
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    7     1      > FE_RESET_R                                           $6      !0, ->45
          2    > > FE_FETCH_R                                                   $6, !1, ->45
    8     3    >   NEW                                                  $7      'DateTime'
          4        SEND_VAR_EX                                                  !1
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !2, $7
    9     7        CLONE                                                ~10     !2
          8        INIT_METHOD_CALL                                             ~10, 'modify'
          9        SEND_VAL_EX                                                  'last+day+of+this+month'
         10        DO_FCALL                                          0  $11     
         11        INIT_METHOD_CALL                                             $11, 'format'
         12        SEND_VAL_EX                                                  'W'
         13        DO_FCALL                                          0  $12     
         14        CAST                                              4  ~13     $12
         15        ASSIGN                                                       !3, ~13
   10    16        IS_SMALLER                                                   !3, 2
         17      > JMPZ                                                         ~15, ->28
         18    >   CLONE                                                ~16     !2
         19        INIT_METHOD_CALL                                             ~16, 'modify'
         20        SEND_VAL_EX                                                  'last+sunday+of+this+month'
         21        DO_FCALL                                          0  $17     
         22        INIT_METHOD_CALL                                             $17, 'format'
         23        SEND_VAL_EX                                                  'W'
         24        DO_FCALL                                          0  $18     
         25        CAST                                              4  ~19     $18
         26        ADD                                                  ~20     ~19, 1
         27        ASSIGN                                                       !3, ~20
   11    28    >   INIT_METHOD_CALL                                             !2, 'format'
         29        SEND_VAL_EX                                                  'W'
         30        DO_FCALL                                          0  $22     
         31        CAST                                              4  ~23     $22
         32        ASSIGN                                                       !2, ~23
   12    33        IS_SMALLER                                                   51, !2
         34      > JMPZ                                                         ~25, ->36
         35    >   ASSIGN                                                       !2, 0
         36    >   SUB                                                  ~27     !3, !2
         37        ADD                                                  ~28     ~27, 1
         38        ASSIGN                                                       !4, ~28
   13    39        ROPE_INIT                                         4  ~31     !1
         40        ROPE_ADD                                          1  ~31     ~31, '+%3D+'
         41        ROPE_ADD                                          2  ~31     ~31, !4
         42        ROPE_END                                          3  ~30     ~31, '%0A'
         43        ECHO                                                         ~30
    7    44      > JMP                                                          ->2
         45    >   FE_FREE                                                      $6
   14    46      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.02 ms | 2662 KiB | 13 Q