3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Function 0 & 1 function monthsBetween(DateTime $date1, DateTime $date2 = NULL) { if (is_null($date2)) { $date2 = new DateTime("now"); } $interval = $date2->diff($date1); return 12 * $interval->y + $interval->m; } // Function 2 & 3 function hasMonthBetween(DateTime $date1, DateTime $date2 = NULL) { return monthsBetween($date1, $date2) > 0; } $startDate = new DateTime('2000-01-11'); $endDate = new DateTime('2000-02-11'); // Function 0 Call echo monthsBetween($startDate, $endDate) . PHP_EOL; // Function 1 Call echo monthsBetween($startDate) . PHP_EOL; // Function 2 Call echo hasMonthBetween($startDate, $endDate) . PHP_EOL; // Function 3 Call echo hasMonthBetween($startDate) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/68Qur
function name:  (null)
number of ops:  31
compiled vars:  !0 = $startDate, !1 = $endDate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $2      'DateTime'
          1        SEND_VAL_EX                                              '2000-01-11'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   18     4        NEW                                              $5      'DateTime'
          5        SEND_VAL_EX                                              '2000-02-11'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $5
   21     8        INIT_FCALL                                               'monthsbetween'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $8      
         12        CONCAT                                           ~9      $8, '%0A'
         13        ECHO                                                     ~9
   24    14        INIT_FCALL                                               'monthsbetween'
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0  $10     
         17        CONCAT                                           ~11     $10, '%0A'
         18        ECHO                                                     ~11
   27    19        INIT_FCALL                                               'hasmonthbetween'
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !1
         22        DO_FCALL                                      0  $12     
         23        CONCAT                                           ~13     $12, '%0A'
         24        ECHO                                                     ~13
   30    25        INIT_FCALL                                               'hasmonthbetween'
         26        SEND_VAR                                                 !0
         27        DO_FCALL                                      0  $14     
         28        CONCAT                                           ~15     $14, '%0A'
         29        ECHO                                                     ~15
   31    30      > RETURN                                                   1

Function monthsbetween:
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 = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/68Qur
function name:  monthsBetween
number of ops:  18
compiled vars:  !0 = $date1, !1 = $date2, !2 = $interval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    5     2        TYPE_CHECK                                    2          !1
          3      > JMPZ                                                     ~3, ->8
    6     4    >   NEW                                              $4      'DateTime'
          5        SEND_VAL_EX                                              'now'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $4
    8     8    >   INIT_METHOD_CALL                                         !1, 'diff'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !2, $7
    9    12        FETCH_OBJ_R                                      ~9      !2, 'y'
         13        MUL                                              ~10     ~9, 12
         14        FETCH_OBJ_R                                      ~11     !2, 'm'
         15        ADD                                              ~12     ~10, ~11
         16      > RETURN                                                   ~12
   10    17*     > RETURN                                                   null

End of function monthsbetween

Function hasmonthbetween:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/68Qur
function name:  hasMonthBetween
number of ops:  9
compiled vars:  !0 = $date1, !1 = $date2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   14     2        INIT_FCALL                                               'monthsbetween'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $2      
          6        IS_SMALLER                                       ~3      0, $2
          7      > RETURN                                                   ~3
   15     8*     > RETURN                                                   null

End of function hasmonthbetween

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.83 ms | 1003 KiB | 18 Q