3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DateTimeFactory { const DATE_INTERVAL = 'PT20M'; const DATE_INTERVAL_FOR_METHOD_3 = '+20 minutes'; // I personally prefer adding DateInterval public static function createDateTimeByInterval1(DateInterval $dateInterval) { // create DateTime, add Date and/or TimeZone in constructor if needed. $dateTime = new DateTime(); return $dateTime->add($dateInterval); } // Using a ISO 8601 String public static function createDateTimeByInterval2($intervalStr) { // create DateTime, add Date and/or TimeZone in constructor if needed. $dateTime = new DateTime(); return $dateTime->add(new DateInterval($intervalStr)); } // Using modify public static function createDateTimeByInterval3($intervalStr) { // create DateTime, add Date and/or TimeZone in constructor if needed. $dateTime = new DateTime(); return $dateTime->modify($intervalStr); } } var_dump( DateTimeFactory::createDateTimeByInterval1(new DateInterval(DateTimeFactory::DATE_INTERVAL)), DateTimeFactory::createDateTimeByInterval2(DateTimeFactory::DATE_INTERVAL), DateTimeFactory::createDateTimeByInterval3(DateTimeFactory::DATE_INTERVAL_FOR_METHOD_3) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JnGR2
function name:  (null)
number of ops:  18
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                               'var_dump'
   34     1        INIT_STATIC_METHOD_CALL                                  'DateTimeFactory', 'createDateTimeByInterval1'
          2        NEW                                              $0      'DateInterval'
          3        SEND_VAL_EX                                              'PT20M'
          4        DO_FCALL                                      0          
          5        SEND_VAR                                                 $0
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
   35     8        INIT_STATIC_METHOD_CALL                                  'DateTimeFactory', 'createDateTimeByInterval2'
          9        SEND_VAL                                                 'PT20M'
         10        DO_FCALL                                      0  $3      
         11        SEND_VAR                                                 $3
   36    12        INIT_STATIC_METHOD_CALL                                  'DateTimeFactory', 'createDateTimeByInterval3'
         13        SEND_VAL                                                 '%2B20+minutes'
         14        DO_FCALL                                      0  $4      
         15        SEND_VAR                                                 $4
         16        DO_ICALL                                                 
   37    17      > RETURN                                                   1

Class DateTimeFactory:
Function createdatetimebyinterval1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JnGR2
function name:  createDateTimeByInterval1
number of ops:  9
compiled vars:  !0 = $dateInterval, !1 = $dateTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   12     1        NEW                                              $2      'DateTime'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
   13     4        INIT_METHOD_CALL                                         !1, 'add'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $5      
          7      > RETURN                                                   $5
   14     8*     > RETURN                                                   null

End of function createdatetimebyinterval1

Function createdatetimebyinterval2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JnGR2
function name:  createDateTimeByInterval2
number of ops:  12
compiled vars:  !0 = $intervalStr, !1 = $dateTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   20     1        NEW                                              $2      'DateTime'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
   21     4        INIT_METHOD_CALL                                         !1, 'add'
          5        NEW                                              $5      'DateInterval'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        SEND_VAR_NO_REF_EX                                       $5
          9        DO_FCALL                                      0  $7      
         10      > RETURN                                                   $7
   22    11*     > RETURN                                                   null

End of function createdatetimebyinterval2

Function createdatetimebyinterval3:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JnGR2
function name:  createDateTimeByInterval3
number of ops:  9
compiled vars:  !0 = $intervalStr, !1 = $dateTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   28     1        NEW                                              $2      'DateTime'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
   29     4        INIT_METHOD_CALL                                         !1, 'modify'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $5      
          7      > RETURN                                                   $5
   30     8*     > RETURN                                                   null

End of function createdatetimebyinterval3

End of class DateTimeFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.61 ms | 1400 KiB | 15 Q