3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @Class : IntervalDate * @Autor : FelipeBarros<felipe.barros.pt@gmail.com> * @Description : Servico responsavel retornar os dias da semana entre o intervalo de duas datas * @Version : 1.0 [2014-09-14] * */ class IntervalDate { private $week_days = [ 'mon' => 'monday', 'tue' => 'tuesday', 'wed' => 'wednesday', 'thu' => 'thursday', 'fri' => 'friday', 'sat' => 'saturday', 'sun' => 'sunday' ]; private $start_date; private $final_date; private $n_diff_days; private $format = 'Y-m-d'; private $result = []; public function __construct($start_date, $final_date) { $this->start_date = new \DateTime($start_date); $this->final_date = new \DateTime($final_date); $this->n_diff_days = $this->final_date->diff($this->start_date)->format('%d'); } public function process($week_days) { if($this->n_diff_days) { for($i = 0; $i <= $this->n_diff_days; $i++) { if($i == 0) { $date = $this->start_date->format($this->format); $week_day = strtolower($this->start_date->format('D')); } else { $new_date = $this->start_date->modify('+1 day'); $date = $new_date->format($this->format); $week_day = strtolower($new_date->format('D')); } if(in_array($this->week_days[$week_day], $week_days)) { $this->result[] = ['date' => $date, 'day' => $this->week_days[$week_day]]; } } } return $this; } public function get() { return $this->result; } } $intervalDate = new IntervalDate('2014-10-01', '2014-10-20'); $week_days = ['monday', 'sunday']; $result = $intervalDate->process($week_days)->get(); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HeWbt
function name:  (null)
number of ops:  16
compiled vars:  !0 = $intervalDate, !1 = $week_days, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   NEW                                              $3      'IntervalDate'
          1        SEND_VAL_EX                                              '2014-10-01'
          2        SEND_VAL_EX                                              '2014-10-20'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   66     5        ASSIGN                                                   !1, <array>
   67     6        INIT_METHOD_CALL                                         !0, 'process'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $7      
          9        INIT_METHOD_CALL                                         $7, 'get'
         10        DO_FCALL                                      0  $8      
         11        ASSIGN                                                   !2, $8
   69    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Class IntervalDate:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HeWbt
function name:  __construct
number of ops:  24
compiled vars:  !0 = $start_date, !1 = $final_date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   31     2        NEW                                              $3      'DateTime'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               'start_date'
          6        OP_DATA                                                  $3
   32     7        NEW                                              $6      'DateTime'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN_OBJ                                               'final_date'
         11        OP_DATA                                                  $6
   33    12        FETCH_OBJ_R                                      ~9      'final_date'
         13        INIT_METHOD_CALL                                         ~9, 'diff'
         14        CHECK_FUNC_ARG                                           
         15        FETCH_OBJ_FUNC_ARG                               $10     'start_date'
         16        SEND_FUNC_ARG                                            $10
         17        DO_FCALL                                      0  $11     
         18        INIT_METHOD_CALL                                         $11, 'format'
         19        SEND_VAL_EX                                              '%25d'
         20        DO_FCALL                                      0  $12     
         21        ASSIGN_OBJ                                               'n_diff_days'
         22        OP_DATA                                                  $12
   34    23      > RETURN                                                   null

End of function __construct

Function process:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 59
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 5
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 23
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 55
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 5
Branch analysis from position: 59
Branch analysis from position: 5
Branch analysis from position: 55
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 55
Branch analysis from position: 48
Branch analysis from position: 55
Branch analysis from position: 59
filename:       /in/HeWbt
function name:  process
number of ops:  62
compiled vars:  !0 = $week_days, !1 = $i, !2 = $date, !3 = $week_day, !4 = $new_date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        FETCH_OBJ_R                                      ~5      'n_diff_days'
          2      > JMPZ                                                     ~5, ->59
   38     3    >   ASSIGN                                                   !1, 0
          4      > JMP                                                      ->56
   40     5    >   IS_EQUAL                                                 !1, 0
          6      > JMPZ                                                     ~7, ->23
   41     7    >   FETCH_OBJ_R                                      ~8      'start_date'
          8        INIT_METHOD_CALL                                         ~8, 'format'
          9        CHECK_FUNC_ARG                                           
         10        FETCH_OBJ_FUNC_ARG                               $9      'format'
         11        SEND_FUNC_ARG                                            $9
         12        DO_FCALL                                      0  $10     
         13        ASSIGN                                                   !2, $10
   42    14        INIT_FCALL                                               'strtolower'
         15        FETCH_OBJ_R                                      ~12     'start_date'
         16        INIT_METHOD_CALL                                         ~12, 'format'
         17        SEND_VAL_EX                                              'D'
         18        DO_FCALL                                      0  $13     
         19        SEND_VAR                                                 $13
         20        DO_ICALL                                         $14     
         21        ASSIGN                                                   !3, $14
         22      > JMP                                                      ->41
   45    23    >   FETCH_OBJ_R                                      ~16     'start_date'
         24        INIT_METHOD_CALL                                         ~16, 'modify'
         25        SEND_VAL_EX                                              '%2B1+day'
         26        DO_FCALL                                      0  $17     
         27        ASSIGN                                                   !4, $17
   46    28        INIT_METHOD_CALL                                         !4, 'format'
         29        CHECK_FUNC_ARG                                           
         30        FETCH_OBJ_FUNC_ARG                               $19     'format'
         31        SEND_FUNC_ARG                                            $19
         32        DO_FCALL                                      0  $20     
         33        ASSIGN                                                   !2, $20
   47    34        INIT_FCALL                                               'strtolower'
         35        INIT_METHOD_CALL                                         !4, 'format'
         36        SEND_VAL_EX                                              'D'
         37        DO_FCALL                                      0  $22     
         38        SEND_VAR                                                 $22
         39        DO_ICALL                                         $23     
         40        ASSIGN                                                   !3, $23
   50    41    >   INIT_FCALL                                               'in_array'
         42        FETCH_OBJ_R                                      ~25     'week_days'
         43        FETCH_DIM_R                                      ~26     ~25, !3
         44        SEND_VAL                                                 ~26
         45        SEND_VAR                                                 !0
         46        DO_ICALL                                         $27     
         47      > JMPZ                                                     $27, ->55
   51    48    >   INIT_ARRAY                                       ~30     !2, 'date'
         49        FETCH_OBJ_R                                      ~31     'week_days'
         50        FETCH_DIM_R                                      ~32     ~31, !3
         51        ADD_ARRAY_ELEMENT                                ~30     ~32, 'day'
         52        FETCH_OBJ_W                                      $28     'result'
         53        ASSIGN_DIM                                               $28
         54        OP_DATA                                                  ~30
   38    55    >   PRE_INC                                                  !1
         56    >   FETCH_OBJ_R                                      ~34     'n_diff_days'
         57        IS_SMALLER_OR_EQUAL                                      !1, ~34
         58      > JMPNZ                                                    ~35, ->5
   56    59    >   FETCH_THIS                                       ~36     
         60      > RETURN                                                   ~36
   57    61*     > RETURN                                                   null

End of function process

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HeWbt
function name:  get
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   FETCH_OBJ_R                                      ~0      'result'
          1      > RETURN                                                   ~0
   61     2*     > RETURN                                                   null

End of function get

End of class IntervalDate.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.68 ms | 1404 KiB | 19 Q