3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param string $from * @param string $to * @return string */ function dateDiffString($from, $to) { $fromDate = new \DateTime($from); $toDate = new \DateTime($to); if($fromDate->format('Y') !== $toDate->format('Y')){ return $fromDate->format('M d Y') . " - " . $toDate->format('M d Y'); } if($fromDate->format('m') !== $toDate->format('m')){ return $fromDate->format('M d') . ' - ' . $toDate->format('M d, Y'); } return $fromDate->format('M d') . ' - ' . $toDate->format('d, Y'); } $from = '2015-03-29'; $to = '2015-04-03'; echo dateDiffString($from, $to) . PHP_EOL; $from = '2015-03-31'; $to = '2015-04-02'; echo dateDiffString($from, $to) . PHP_EOL; $from = '2015-03-05'; $to = '2015-03-07'; echo dateDiffString($from, $to) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lLTe6
function name:  (null)
number of ops:  25
compiled vars:  !0 = $from, !1 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, '2015-03-29'
   21     1        ASSIGN                                                   !1, '2015-04-03'
   22     2        INIT_FCALL                                               'datediffstring'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      $4, '%0A'
          7        ECHO                                                     ~5
   24     8        ASSIGN                                                   !0, '2015-03-31'
   25     9        ASSIGN                                                   !1, '2015-04-02'
   26    10        INIT_FCALL                                               'datediffstring'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0  $8      
         14        CONCAT                                           ~9      $8, '%0A'
         15        ECHO                                                     ~9
   28    16        ASSIGN                                                   !0, '2015-03-05'
   29    17        ASSIGN                                                   !1, '2015-03-07'
   30    18        INIT_FCALL                                               'datediffstring'
         19        SEND_VAR                                                 !0
         20        SEND_VAR                                                 !1
         21        DO_FCALL                                      0  $12     
         22        CONCAT                                           ~13     $12, '%0A'
         23        ECHO                                                     ~13
         24      > RETURN                                                   1

Function datediffstring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 27
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 44
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lLTe6
function name:  dateDiffString
number of ops:  54
compiled vars:  !0 = $from, !1 = $to, !2 = $fromDate, !3 = $toDate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        NEW                                              $4      'DateTime'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $4
   10     6        NEW                                              $7      'DateTime'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $7
   11    10        INIT_METHOD_CALL                                         !2, 'format'
         11        SEND_VAL_EX                                              'Y'
         12        DO_FCALL                                      0  $10     
         13        INIT_METHOD_CALL                                         !3, 'format'
         14        SEND_VAL_EX                                              'Y'
         15        DO_FCALL                                      0  $11     
         16        IS_NOT_IDENTICAL                                         $10, $11
         17      > JMPZ                                                     ~12, ->27
   12    18    >   INIT_METHOD_CALL                                         !2, 'format'
         19        SEND_VAL_EX                                              'M+d+Y'
         20        DO_FCALL                                      0  $13     
         21        CONCAT                                           ~14     $13, '+-+'
         22        INIT_METHOD_CALL                                         !3, 'format'
         23        SEND_VAL_EX                                              'M+d+Y'
         24        DO_FCALL                                      0  $15     
         25        CONCAT                                           ~16     ~14, $15
         26      > RETURN                                                   ~16
   14    27    >   INIT_METHOD_CALL                                         !2, 'format'
         28        SEND_VAL_EX                                              'm'
         29        DO_FCALL                                      0  $17     
         30        INIT_METHOD_CALL                                         !3, 'format'
         31        SEND_VAL_EX                                              'm'
         32        DO_FCALL                                      0  $18     
         33        IS_NOT_IDENTICAL                                         $17, $18
         34      > JMPZ                                                     ~19, ->44
   15    35    >   INIT_METHOD_CALL                                         !2, 'format'
         36        SEND_VAL_EX                                              'M+d'
         37        DO_FCALL                                      0  $20     
         38        CONCAT                                           ~21     $20, '+-+'
         39        INIT_METHOD_CALL                                         !3, 'format'
         40        SEND_VAL_EX                                              'M+d%2C+Y'
         41        DO_FCALL                                      0  $22     
         42        CONCAT                                           ~23     ~21, $22
         43      > RETURN                                                   ~23
   17    44    >   INIT_METHOD_CALL                                         !2, 'format'
         45        SEND_VAL_EX                                              'M+d'
         46        DO_FCALL                                      0  $24     
         47        CONCAT                                           ~25     $24, '+-+'
         48        INIT_METHOD_CALL                                         !3, 'format'
         49        SEND_VAL_EX                                              'd%2C+Y'
         50        DO_FCALL                                      0  $26     
         51        CONCAT                                           ~27     ~25, $26
         52      > RETURN                                                   ~27
   18    53*     > RETURN                                                   null

End of function datediffstring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.52 ms | 1403 KiB | 16 Q