3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('America/New_York'); $initialDate = DateTime::createFromFormat('U', '1409611999'); $initialDate = new DateTimeExtended($initialDate, new DateTimezone('UTC')); $firstDayofWeek = clone $initialDate; $lastDayofWeek = clone $initialDate; $firstDayofWeek->setDayOfWeek('Monday', DateTimeExtended::WEEK_CURRENT); $lastDayofWeek->setDayOfWeek('Sunday', DateTimeExtended::WEEK_NEXT); 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/BXahH
function name:  (null)
number of ops:  35
compiled vars:  !0 = $initialDate, !1 = $firstDayofWeek, !2 = $lastDayofWeek
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'date_default_timezone_set'
          1        SEND_VAL                                                 'America%2FNew_York'
          2        DO_ICALL                                                 
    4     3        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          4        SEND_VAL                                                 'U'
          5        SEND_VAL                                                 '1409611999'
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !0, $4
    5     8        NEW                                              $6      'DateTimeExtended'
          9        SEND_VAR_EX                                              !0
         10        NEW                                              $7      'DateTimezone'
         11        SEND_VAL_EX                                              'UTC'
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $7
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !0, $6
    6    16        CLONE                                            ~11     !0
         17        ASSIGN                                                   !1, ~11
    7    18        CLONE                                            ~13     !0
         19        ASSIGN                                                   !2, ~13
    8    20        INIT_METHOD_CALL                                         !1, 'setDayOfWeek'
         21        SEND_VAL_EX                                              'Monday'
         22        FETCH_CLASS_CONSTANT                             ~15     'DateTimeExtended', 'WEEK_CURRENT'
         23        SEND_VAL_EX                                              ~15
         24        DO_FCALL                                      0          
    9    25        INIT_METHOD_CALL                                         !2, 'setDayOfWeek'
         26        SEND_VAL_EX                                              'Sunday'
         27        FETCH_CLASS_CONSTANT                             ~17     'DateTimeExtended', 'WEEK_NEXT'
         28        SEND_VAL_EX                                              ~17
         29        DO_FCALL                                      0          
   11    30        INIT_FCALL                                               'var_dump'
         31        SEND_VAR                                                 !1
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                                 
   89    34      > 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/BXahH
function name:  __construct
number of ops:  36
compiled vars:  !0 = $args, !1 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   FUNC_GET_ARGS                                    ~2      
          1        ASSIGN                                                   !0, ~2
   32     2        ISSET_ISEMPTY_CV                                         !0
          3      > JMPZ                                                     ~4, ->8
   33     4    >   NEW                                              $5      'Exception'
          5        SEND_VAL_EX                                              'No+argument+supplied%21'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $5
   35     8    >   FETCH_DIM_R                                      ~7      !0, 0
          9        INSTANCEOF                                               ~7, 'DateTime'
         10      > JMPZ                                                     ~8, ->23
   36    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
   38    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          
   40    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/BXahH
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
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   44     2        INIT_FCALL                                               'strtolower'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !0, $6
   45     6        TYPE_CHECK                                   16  ~8      !0
          7        BOOL_NOT                                         ~9      ~8
          8      > JMPZ                                                     ~9, ->15
   46     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
   48    15    >   INIT_METHOD_CALL                                         'format'
         16        SEND_VAL_EX                                              'w'
         17        DO_FCALL                                      0  $13     
         18        ASSIGN                                                   !2, $13
   50    19        FETCH_CLASS_CONSTANT                             ~16     'WEEK_CURRENT'
         20        IS_EQUAL                                                 !1, ~16
         21      > JMPNZ                                                    ~15, ->29
   53    22    >   FETCH_CLASS_CONSTANT                             ~17     'WEEK_NEXT'
         23        IS_EQUAL                                                 !1, ~17
         24      > JMPNZ                                                    ~15, ->32
   63    25    >   FETCH_CLASS_CONSTANT                             ~18     'WEEK_PREVIOUS'
         26        IS_EQUAL                                                 !1, ~18
         27      > JMPNZ                                                    ~15, ->44
         28    > > JMP                                                      ->57
   51    29    >   SUB                                              ~19     !0, !2
         30        ASSIGN                                                   !3, ~19
   52    31      > JMP                                                      ->61
   54    32    >   ASSIGN                                                   !3, 1
   55    33      > JMP                                                      ->41
   56    34    >   ADD                                              ~22     !2, 1
         35        MOD                                              ~23     ~22, 7
         36        ASSIGN                                                   !2, ~23
   57    37        IS_EQUAL                                                 !2, !0
         38      > JMPZ                                                     ~25, ->40
   58    39    > > JMP                                                      ->43
   60    40    >   PRE_INC                                                  !3
   55    41    >   IS_SMALLER_OR_EQUAL                                      !3, 7
         42      > JMPNZ                                                    ~27, ->34
   62    43    > > JMP                                                      ->61
   64    44    >   ASSIGN                                                   !3, -1
   65    45      > JMP                                                      ->54
   66    46    >   ASSIGN_OP                                     2          !2, 1
   67    47        IS_SMALLER                                               !2, 0
         48      > JMPZ                                                     ~30, ->50
   68    49    >   ASSIGN                                                   !2, 6
   70    50    >   IS_EQUAL                                                 !2, !0
         51      > JMPZ                                                     ~32, ->53
   71    52    > > JMP                                                      ->56
   73    53    >   PRE_DEC                                                  !3
   65    54    >   IS_SMALLER_OR_EQUAL                                      -7, !3
         55      > JMPNZ                                                    ~34, ->46
   75    56    > > JMP                                                      ->61
   77    57    >   NEW                                              $35     'Exception'
         58        SEND_VAL_EX                                              'Invalid+margin+supplied%21'
         59        DO_FCALL                                      0          
         60      > THROW                                         0          $35
   79    61    >   INIT_FCALL                                               'abs'
         62        SEND_VAR                                                 !3
         63        DO_ICALL                                         $37     
         64        ASSIGN                                                   !4, $37
   80    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
   81    72        IS_SMALLER                                               !3, 0
         73      > JMPZ                                                     ~45, ->78
   82    74    >   INIT_METHOD_CALL                                         'sub'
         75        SEND_VAR_EX                                              !5
         76        DO_FCALL                                      0          
         77      > JMP                                                      ->81
   84    78    >   INIT_METHOD_CALL                                         'add'
         79        SEND_VAR_EX                                              !5
         80        DO_FCALL                                      0          
   86    81    >   FETCH_THIS                                       ~48     
         82      > RETURN                                                   ~48
   87    83*     > RETURN                                                   null

End of function setdayofweek

End of class DateTimeExtended.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.34 ms | 1412 KiB | 23 Q