3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BusinessDaysCalculator { const MONDAY = 1; const TUESDAY = 2; const WEDNESDAY = 3; const THURSDAY = 4; const FRIDAY = 5; const SATURDAY = 6; const SUNDAY = 7; /** * @param DateTime $startDate Date to start calculations from * @param DateTime[] $holidays Array of holidays, holidays are no conisdered business days. * @param int[] $nonBusinessDays Array of days of the week which are not business days. */ public function __construct(DateTime $startDate, array $holidays, array $nonBusinessDays) { $this->date = $startDate; $this->holidays = $holidays; $this->nonBusinessDays = $nonBusinessDays; } public function addBusinessDays($howManyDays) { $i = 0; while ($i < $howManyDays) { $this->date->modify("+1 day"); if ($this->isBusinessDay($this->date)) { $i++; } } } public function getDate() { return $this->date; } private function isBusinessDay(DateTime $date) { if (in_array((int)$date->format('N'), $this->nonBusinessDays)) { return false; //Date is a nonBusinessDay. } foreach ($this->holidays as $day) { if ($date->format('Y-m-d') == $day->format('Y-m-d')) { return false; //Date is a holiday. } } return true; //Date is a business day. } } $calculator = new BusinessDaysCalculator( new DateTime(), // Today [new DateTime("2014-06-01"), new DateTime("2014-06-02")], [BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::FRIDAY] ); $calculator->addBusinessDays(3); // Add three business days var_dump($calculator->getDate());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHEmG
function name:  (null)
number of ops:  25
compiled vars:  !0 = $calculator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   NEW                                              $1      'BusinessDaysCalculator'
   52     1        NEW                                              $2      'DateTime'
          2        DO_FCALL                                      0          
          3        SEND_VAR_NO_REF_EX                                       $2
   53     4        NEW                                              $4      'DateTime'
          5        SEND_VAL_EX                                              '2014-06-01'
          6        DO_FCALL                                      0          
          7        INIT_ARRAY                                       ~6      $4
          8        NEW                                              $7      'DateTime'
          9        SEND_VAL_EX                                              '2014-06-02'
         10        DO_FCALL                                      0          
         11        ADD_ARRAY_ELEMENT                                ~6      $7
         12        SEND_VAL_EX                                              ~6
   54    13        SEND_VAL_EX                                              <array>
         14        DO_FCALL                                      0          
   51    15        ASSIGN                                                   !0, $1
   57    16        INIT_METHOD_CALL                                         !0, 'addBusinessDays'
         17        SEND_VAL_EX                                              3
         18        DO_FCALL                                      0          
   59    19        INIT_FCALL                                               'var_dump'
         20        INIT_METHOD_CALL                                         !0, 'getDate'
         21        DO_FCALL                                      0  $12     
         22        SEND_VAR                                                 $12
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Class BusinessDaysCalculator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NHEmG
function name:  __construct
number of ops:  10
compiled vars:  !0 = $startDate, !1 = $holidays, !2 = $nonBusinessDays
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   19     3        ASSIGN_OBJ                                               'date'
          4        OP_DATA                                                  !0
   20     5        ASSIGN_OBJ                                               'holidays'
          6        OP_DATA                                                  !1
   21     7        ASSIGN_OBJ                                               'nonBusinessDays'
          8        OP_DATA                                                  !2
   22     9      > RETURN                                                   null

End of function __construct

Function addbusinessdays:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 3
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 3
Branch analysis from position: 16
Branch analysis from position: 3
Branch analysis from position: 14
filename:       /in/NHEmG
function name:  addBusinessDays
number of ops:  17
compiled vars:  !0 = $howManyDays, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        ASSIGN                                                   !1, 0
   26     2      > JMP                                                      ->14
   27     3    >   FETCH_OBJ_R                                      ~3      'date'
          4        INIT_METHOD_CALL                                         ~3, 'modify'
          5        SEND_VAL_EX                                              '%2B1+day'
          6        DO_FCALL                                      0          
   28     7        INIT_METHOD_CALL                                         'isBusinessDay'
          8        CHECK_FUNC_ARG                                           
          9        FETCH_OBJ_FUNC_ARG                               $5      'date'
         10        SEND_FUNC_ARG                                            $5
         11        DO_FCALL                                      0  $6      
         12      > JMPZ                                                     $6, ->14
   29    13    >   PRE_INC                                                  !1
   26    14    >   IS_SMALLER                                               !1, !0
         15      > JMPNZ                                                    ~8, ->3
   32    16    > > RETURN                                                   null

End of function addbusinessdays

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

End of function getdate

Function isbusinessday:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 26
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/NHEmG
function name:  isBusinessDay
number of ops:  29
compiled vars:  !0 = $date, !1 = $day
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        INIT_FCALL                                               'in_array'
          2        INIT_METHOD_CALL                                         !0, 'format'
          3        SEND_VAL_EX                                              'N'
          4        DO_FCALL                                      0  $2      
          5        CAST                                          4  ~3      $2
          6        SEND_VAL                                                 ~3
          7        FETCH_OBJ_R                                      ~4      'nonBusinessDays'
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10      > JMPZ                                                     $5, ->12
   40    11    > > RETURN                                                   <false>
   42    12    >   FETCH_OBJ_R                                      ~6      'holidays'
         13      > FE_RESET_R                                       $7      ~6, ->26
         14    > > FE_FETCH_R                                               $7, !1, ->26
   43    15    >   INIT_METHOD_CALL                                         !0, 'format'
         16        SEND_VAL_EX                                              'Y-m-d'
         17        DO_FCALL                                      0  $8      
         18        INIT_METHOD_CALL                                         !1, 'format'
         19        SEND_VAL_EX                                              'Y-m-d'
         20        DO_FCALL                                      0  $9      
         21        IS_EQUAL                                                 $8, $9
         22      > JMPZ                                                     ~10, ->25
   44    23    >   FE_FREE                                                  $7
         24      > RETURN                                                   <false>
   42    25    > > JMP                                                      ->14
         26    >   FE_FREE                                                  $7
   47    27      > RETURN                                                   <true>
   48    28*     > RETURN                                                   null

End of function isbusinessday

End of class BusinessDaysCalculator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.61 ms | 1396 KiB | 17 Q