3v4l.org

run code in 300+ PHP versions simultaneously
<?php function closestDate($day){ $day = ucfirst($day); if(date('l', time()) == $day) return date("Y-m-d", time()); else if(abs(time()-strtotime('next '.$day)) < abs(time()-strtotime('last '.$day))) return date("Y-m-d", strtotime('next '.$day)); else return date("Y-m-d", strtotime('last '.$day)); } echo closestDate('Monday');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/G3LM3
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'closestdate'
          1        SEND_VAL                                                 'Monday'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function closestdate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 53
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/G3LM3
function name:  closestDate
number of ops:  63
compiled vars:  !0 = $day
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'ucfirst'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
    5     5        INIT_FCALL                                               'date'
          6        SEND_VAL                                                 'l'
          7        INIT_FCALL                                               'time'
          8        DO_ICALL                                         $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                         $4      
         11        IS_EQUAL                                                 !0, $4
         12      > JMPZ                                                     ~5, ->21
    6    13    >   INIT_FCALL                                               'date'
         14        SEND_VAL                                                 'Y-m-d'
         15        INIT_FCALL                                               'time'
         16        DO_ICALL                                         $6      
         17        SEND_VAR                                                 $6
         18        DO_ICALL                                         $7      
         19      > RETURN                                                   $7
         20*       JMP                                                      ->62
    7    21    >   INIT_FCALL                                               'abs'
         22        INIT_FCALL                                               'time'
         23        DO_ICALL                                         $8      
         24        INIT_FCALL                                               'strtotime'
         25        CONCAT                                           ~9      'next+', !0
         26        SEND_VAL                                                 ~9
         27        DO_ICALL                                         $10     
         28        SUB                                              ~11     $8, $10
         29        SEND_VAL                                                 ~11
         30        DO_ICALL                                         $12     
         31        INIT_FCALL                                               'abs'
         32        INIT_FCALL                                               'time'
         33        DO_ICALL                                         $13     
         34        INIT_FCALL                                               'strtotime'
         35        CONCAT                                           ~14     'last+', !0
         36        SEND_VAL                                                 ~14
         37        DO_ICALL                                         $15     
         38        SUB                                              ~16     $13, $15
         39        SEND_VAL                                                 ~16
         40        DO_ICALL                                         $17     
         41        IS_SMALLER                                               $12, $17
         42      > JMPZ                                                     ~18, ->53
    8    43    >   INIT_FCALL                                               'date'
         44        SEND_VAL                                                 'Y-m-d'
         45        INIT_FCALL                                               'strtotime'
         46        CONCAT                                           ~19     'next+', !0
         47        SEND_VAL                                                 ~19
         48        DO_ICALL                                         $20     
         49        SEND_VAR                                                 $20
         50        DO_ICALL                                         $21     
         51      > RETURN                                                   $21
         52*       JMP                                                      ->62
   10    53    >   INIT_FCALL                                               'date'
         54        SEND_VAL                                                 'Y-m-d'
         55        INIT_FCALL                                               'strtotime'
         56        CONCAT                                           ~22     'last+', !0
         57        SEND_VAL                                                 ~22
         58        DO_ICALL                                         $23     
         59        SEND_VAR                                                 $23
         60        DO_ICALL                                         $24     
         61      > RETURN                                                   $24
   12    62*     > RETURN                                                   null

End of function closestdate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.07 ms | 1403 KiB | 24 Q