3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getLastMonth(DateTime $date) { //avoid side affects $date = clone $date; $date->modify('first day of last month'); return array( 'first' => $date->format('Y-m-d'), 'last' => $date->format('Y-m-t'), ); } var_dump(getLastMonth(new \DateTime()));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ELIrA
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'getlastmonth'
          2        NEW                                              $0      'DateTime'
          3        DO_FCALL                                      0          
          4        SEND_VAR                                                 $0
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function getlastmonth:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ELIrA
function name:  getLastMonth
number of ops:  16
compiled vars:  !0 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    5     1        CLONE                                            ~1      !0
          2        ASSIGN                                                   !0, ~1
    6     3        INIT_METHOD_CALL                                         !0, 'modify'
          4        SEND_VAL_EX                                              'first+day+of+last+month'
          5        DO_FCALL                                      0          
    8     6        INIT_METHOD_CALL                                         !0, 'format'
          7        SEND_VAL_EX                                              'Y-m-d'
          8        DO_FCALL                                      0  $4      
          9        INIT_ARRAY                                       ~5      $4, 'first'
    9    10        INIT_METHOD_CALL                                         !0, 'format'
         11        SEND_VAL_EX                                              'Y-m-t'
         12        DO_FCALL                                      0  $6      
         13        ADD_ARRAY_ELEMENT                                ~5      $6, 'last'
         14      > RETURN                                                   ~5
   11    15*     > RETURN                                                   null

End of function getlastmonth

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.19 ms | 1389 KiB | 16 Q