3v4l.org

run code in 300+ PHP versions simultaneously
<?php $initialDate = DateTime::createFromFormat('U', '1409611999'); $initialDate = new DateTimeExtended($initialDate); $firstDayofWeek = clone $initialDate; $lastDayofWeek = clone $initialDate; $firstDayofWeek->setDayOfWeek('Monday', DateTimeExtended::WEEK_CURRENT); $lastDayofWeek->setDayOfWeek('Sunday', DateTimeExtended::WEEK_CURRENT); var_dump($firstDayofWeek, $lastDayofWeek); class DateTimeExtended Extends DateTime { const WEEK_CURRENT = 0; const WEEK_NEXT = 1; const WEEK_PREVIOUS = 2; protected static $days_of_week = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', ); public function __construct() { $args = func_get_args(); if (empty($args)) { throw new Exception('No argument supplied!'); } if ($args[0] instanceof DateTime) { parent::__construct($args[0]->format('Y-m-d H:i:s'), $args[0]->getTimezone()); } else { parent::__construct($args[0], isset($arg[1]) ? $arg[1] : null); } } public function setDayOfWeek($day, $margin = 0) { $day = strtolower($day); if (!is_int($day)) { $day = array_search($day, static::$days_of_week); } $current_day = $this->format('w'); switch($margin) { case static::WEEK_CURRENT: $interval = $day - $current_day; break; case static::WEEK_NEXT: $interval = 1; while($interval <= 7) { $current_day = ($current_day + 1) % 7; if ($current_day == $day) { break; } $interval++; } break; case static::WEEK_PREVIOUS: $interval = -1; while($interval >= -7) { $current_day -= 1; if ($current_day < 0) { $current_day = 6; } if ($current_day == $day) { break; } $interval--; } break; default: throw new Exception('Invalid margin supplied!'); } $i = abs($interval); $days = new DateInterval("P{$i}D"); if ($interval < 0) { $this->sub($days); } else { $this->add($days); } return $this; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aqTVO
function name:  (null)
number of ops:  28
compiled vars:  !0 = $initialDate, !1 = $firstDayofWeek, !2 = $lastDayofWeek
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          1        SEND_VAL                                                 'U'
          2        SEND_VAL                                                 '1409611999'
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !0, $3
    4     5        NEW                                              $5      'DateTimeExtended'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !0, $5
    5     9        CLONE                                            ~8      !0
         10        ASSIGN                                                   !1, ~8
    6    11        CLONE                                            ~10     !0
         12        ASSIGN                                                   !2, ~10
    7    13        INIT_METHOD_CALL                                         !1, 'setDayOfWeek'
         14        SEND_VAL_EX                                              'Monday'
         15        FETCH_CLASS_CONSTANT                             ~12     'DateTimeExtended', 'WEEK_CURRENT'
         16        SEND_VAL_EX                                              ~12
         17        DO_FCALL                                      0          
    8    18        INIT_METHOD_CALL                                         !2, 'setDayOfWeek'
         19        SEND_VAL_EX                                              'Sunday'
         20        FETCH_CLASS_CONSTANT                             ~14     'DateTimeExtended', 'WEEK_CURRENT'
         21        SEND_VAL_EX                                              ~14
         22        DO_FCALL                                      0          
   10    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !1
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                                 
   88    27      > RETURN                                                   1

Class DateTimeExtended:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aqTVO
function name:  __construct
number of ops:  36
compiled vars:  !0 = $args, !1 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FUNC_GET_ARGS                                    ~2      
          1        ASSIGN                                                   !0, ~2
   31     2        ISSET_ISEMPTY_CV                                         !0
          3      > JMPZ                                                     ~4, ->8
   32     4    >   NEW                                              $5      'Exception'
          5        SEND_VAL_EX                                              'No+argument+supplied%21'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $5
   34     8    >   FETCH_DIM_R                                      ~7      !0, 0
          9        INSTANCEOF                                               ~7, 'DateTime'
         10      > JMPZ                                                     ~8, ->23
   35    11    >   INIT_STATIC_METHOD_CALL                                  
         12        FETCH_DIM_R                                      ~9      !0, 0
         13        INIT_METHOD_CALL                                         ~9, 'format'
         14        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         15        DO_FCALL                                      0  $10     
         16        SEND_VAR_NO_REF_EX                                       $10
         17        FETCH_DIM_R                                      ~11     !0, 0
         18        INIT_METHOD_CALL                                         ~11, 'getTimezone'
         19        DO_FCALL                                      0  $12     
         20        SEND_VAR_NO_REF_EX                                       $12
         21        DO_FCALL                                      0          
         22      > JMP                                                      ->35
   37    23    >   INIT_STATIC_METHOD_CALL                                  
         24        CHECK_FUNC_ARG                                           
         25        FETCH_DIM_FUNC_ARG                               $14     !0, 0
         26        SEND_FUNC_ARG                                            $14
         27        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 1
         28      > JMPZ                                                     ~15, ->32
         29    >   FETCH_DIM_R                                      ~16     !1, 1
         30        QM_ASSIGN                                        ~17     ~16
         31      > JMP                                                      ->33
         32    >   QM_ASSIGN                                        ~17     null
         33    >   SEND_VAL_EX                                              ~17
         34        DO_FCALL                                      0          
   39    35    > > RETURN                                                   null

End of function __construct

Function setdayofweek:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 44
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 46
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 78
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 50
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 53
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 46
Branch analysis from position: 56
Branch analysis from position: 46
Branch analysis from position: 50
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 34
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 40
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 34
Branch analysis from position: 43
Branch analysis from position: 34
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 15
filename:       /in/aqTVO
function name:  setDayOfWeek
number of ops:  84
compiled vars:  !0 = $day, !1 = $margin, !2 = $current_day, !3 = $interval, !4 = $i, !5 = $days
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   43     2        INIT_FCALL                                               'strtolower'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !0, $6
   44     6        TYPE_CHECK                                   16  ~8      !0
          7        BOOL_NOT                                         ~9      ~8
          8      > JMPZ                                                     ~9, ->15
   45     9    >   INIT_FCALL                                               'array_search'
         10        SEND_VAR                                                 !0
         11        FETCH_STATIC_PROP_R          unknown             ~10     'days_of_week'
         12        SEND_VAL                                                 ~10
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !0, $11
   47    15    >   INIT_METHOD_CALL                                         'format'
         16        SEND_VAL_EX                                              'w'
         17        DO_FCALL                                      0  $13     
         18        ASSIGN                                                   !2, $13
   49    19        FETCH_CLASS_CONSTANT                             ~16     'WEEK_CURRENT'
         20        IS_EQUAL                                                 !1, ~16
         21      > JMPNZ                                                    ~15, ->29
   52    22    >   FETCH_CLASS_CONSTANT                             ~17     'WEEK_NEXT'
         23        IS_EQUAL                                                 !1, ~17
         24      > JMPNZ                                                    ~15, ->32
   62    25    >   FETCH_CLASS_CONSTANT                             ~18     'WEEK_PREVIOUS'
         26        IS_EQUAL                                                 !1, ~18
         27      > JMPNZ                                                    ~15, ->44
         28    > > JMP                                                      ->57
   50    29    >   SUB                                              ~19     !0, !2
         30        ASSIGN                                                   !3, ~19
   51    31      > JMP                                                      ->61
   53    32    >   ASSIGN                                                   !3, 1
   54    33      > JMP                                                      ->41
   55    34    >   ADD                                              ~22     !2, 1
         35        MOD                                              ~23     ~22, 7
         36        ASSIGN                                                   !2, ~23
   56    37        IS_EQUAL                                                 !2, !0
         38      > JMPZ                                                     ~25, ->40
   57    39    > > JMP                                                      ->43
   59    40    >   PRE_INC                                                  !3
   54    41    >   IS_SMALLER_OR_EQUAL                                      !3, 7
         42      > JMPNZ                                                    ~27, ->34
   61    43    > > JMP                                                      ->61
   63    44    >   ASSIGN                                                   !3, -1
   64    45      > JMP                                                      ->54
   65    46    >   ASSIGN_OP                                     2          !2, 1
   66    47        IS_SMALLER                                               !2, 0
         48      > JMPZ                                                     ~30, ->50
   67    49    >   ASSIGN                                                   !2, 6
   69    50    >   IS_EQUAL                                                 !2, !0
         51      > JMPZ                                                     ~32, ->53
   70    52    > > JMP                                                      ->56
   72    53    >   PRE_DEC                                                  !3
   64    54    >   IS_SMALLER_OR_EQUAL                                      -7, !3
         55      > JMPNZ                                                    ~34, ->46
   74    56    > > JMP                                                      ->61
   76    57    >   NEW                                              $35     'Exception'
         58        SEND_VAL_EX                                              'Invalid+margin+supplied%21'
         59        DO_FCALL                                      0          
         60      > THROW                                         0          $35
   78    61    >   INIT_FCALL                                               'abs'
         62        SEND_VAR                                                 !3
         63        DO_ICALL                                         $37     
         64        ASSIGN                                                   !4, $37
   79    65        NEW                                              $39     'DateInterval'
         66        ROPE_INIT                                     3  ~41     'P'
         67        ROPE_ADD                                      1  ~41     ~41, !4
         68        ROPE_END                                      2  ~40     ~41, 'D'
         69        SEND_VAL_EX                                              ~40
         70        DO_FCALL                                      0          
         71        ASSIGN                                                   !5, $39
   80    72        IS_SMALLER                                               !3, 0
         73      > JMPZ                                                     ~45, ->78
   81    74    >   INIT_METHOD_CALL                                         'sub'
         75        SEND_VAR_EX                                              !5
         76        DO_FCALL                                      0          
         77      > JMP                                                      ->81
   83    78    >   INIT_METHOD_CALL                                         'add'
         79        SEND_VAR_EX                                              !5
         80        DO_FCALL                                      0          
   85    81    >   FETCH_THIS                                       ~48     
         82      > RETURN                                                   ~48
   86    83*     > RETURN                                                   null

End of function setdayofweek

End of class DateTimeExtended.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.89 ms | 1412 KiB | 21 Q