3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getStartOfWeekDate($date = null) { if ($date instanceof \DateTime) { $date = clone $date; } else if (!$date) { $date = new \DateTime(); } else { $date = new \DateTime($date); } $date->setTime(0, 0, 0); if ($date->format('N') == 1) { // If the date is already a Monday, return it as-is return $date; } else { // Otherwise, return the date of the nearest Monday in the past // This includes Sunday in the previous week instead of it being the start of a new week return $date->modify('last monday'); } } echo getStartOfWeekDate(new \DateTime('2020-12-06'))->format('Y-m-d');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6n50U
function name:  (null)
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'getstartofweekdate'
          1        NEW                                              $0      'DateTime'
          2        SEND_VAL_EX                                              '2020-12-06'
          3        DO_FCALL                                      0          
          4        SEND_VAR                                                 $0
          5        DO_FCALL                                      0  $2      
          6        INIT_METHOD_CALL                                         $2, 'format'
          7        SEND_VAL_EX                                              'Y-m-d'
          8        DO_FCALL                                      0  $3      
          9        ECHO                                                     $3
         10      > RETURN                                                   1

Function getstartofweekdate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
Branch analysis from position: 28
filename:       /in/6n50U
function name:  getStartOfWeekDate
number of ops:  33
compiled vars:  !0 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV_INIT                                        !0      null
    4     1        INSTANCEOF                                               !0, 'DateTime'
          2      > JMPZ                                                     ~1, ->6
    5     3    >   CLONE                                            ~2      !0
          4        ASSIGN                                                   !0, ~2
          5      > JMP                                                      ->16
    6     6    >   BOOL_NOT                                         ~4      !0
          7      > JMPZ                                                     ~4, ->12
    7     8    >   NEW                                              $5      'DateTime'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !0, $5
         11      > JMP                                                      ->16
    9    12    >   NEW                                              $8      'DateTime'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !0, $8
   12    16    >   INIT_METHOD_CALL                                         !0, 'setTime'
         17        SEND_VAL_EX                                              0
         18        SEND_VAL_EX                                              0
         19        SEND_VAL_EX                                              0
         20        DO_FCALL                                      0          
   14    21        INIT_METHOD_CALL                                         !0, 'format'
         22        SEND_VAL_EX                                              'N'
         23        DO_FCALL                                      0  $12     
         24        IS_EQUAL                                                 $12, 1
         25      > JMPZ                                                     ~13, ->28
   16    26    > > RETURN                                                   !0
         27*       JMP                                                      ->32
   20    28    >   INIT_METHOD_CALL                                         !0, 'modify'
         29        SEND_VAL_EX                                              'last+monday'
         30        DO_FCALL                                      0  $14     
         31      > RETURN                                                   $14
   22    32*     > RETURN                                                   null

End of function getstartofweekdate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.88 ms | 1403 KiB | 14 Q