3v4l.org

run code in 500+ PHP versions simultaneously
<?php readonly class MySqlTime { public function __construct( public int $hours, public int $minutes, public int $seconds, ) { } public static function fromMySqlTimeAsDurationInDay(string $time): self { [$hours, $minutes, $seconds] = array_map('intval', explode(':', $time)); // Ensure only positive values on a single day. // MySql should already be throwing errors about minutes or seconds being out of range, so we don't // need to check those. // The seconds could include decimals, however for this purpose we are ignoring them. if ($hours > 23 || $hours < 0) { throw new InvalidArgumentException('Hours must be between 0 and 23'); } return new self($hours, $minutes, $seconds); } public function toDateTime(DateTimeInterface $dateTime = null) : DateTimeInterface { $dateTime ??= new DateTimeImmutable(); return $dateTime->setTime($this->hours, $this->minutes, $this->seconds); } } var_dump(MySqlTime::fromMySqlTimeAsDurationInDay('12:34:56')->toDateTime());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B6mr4
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_STATIC_METHOD_CALL                                      'MySqlTime', 'fromMySqlTimeAsDurationInDay'
          2        SEND_VAL                                                     '12%3A34%3A56'
          3        DO_FCALL                                          0  $0      
          4        INIT_METHOD_CALL                                             $0, 'toDateTime'
          5        DO_FCALL                                          0  $1      
          6        SEND_VAR                                                     $1
          7        DO_ICALL                                                     
          8      > RETURN                                                       1

Class MySqlTime:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B6mr4
function name:  __construct
number of ops:  10
compiled vars:  !0 = $hours, !1 = $minutes, !2 = $seconds
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
    7     1        RECV                                                 !1      
    8     2        RECV                                                 !2      
    6     3        ASSIGN_OBJ                                                   'hours'
          4        OP_DATA                                                      !0
    7     5        ASSIGN_OBJ                                                   'minutes'
          6        OP_DATA                                                      !1
    8     7        ASSIGN_OBJ                                                   'seconds'
          8        OP_DATA                                                      !2
   10     9      > RETURN                                                       null

End of function __construct

Function frommysqltimeasdurationinday:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/B6mr4
function name:  fromMySqlTimeAsDurationInDay
number of ops:  34
compiled vars:  !0 = $time, !1 = $hours, !2 = $minutes, !3 = $seconds
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
   14     1        INIT_FCALL                                                   'array_map'
          2        SEND_VAL                                                     'intval'
          3        INIT_FCALL                                                   'explode'
          4        SEND_VAL                                                     '%3A'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $4      
          7        SEND_VAR                                                     $4
          8        DO_ICALL                                             $5      
          9        FETCH_LIST_R                                         $6      $5, 0
         10        ASSIGN                                                       !1, $6
         11        FETCH_LIST_R                                         $8      $5, 1
         12        ASSIGN                                                       !2, $8
         13        FETCH_LIST_R                                         $10     $5, 2
         14        ASSIGN                                                       !3, $10
         15        FREE                                                         $5
   20    16        IS_SMALLER                                           ~12     23, !1
         17      > JMPNZ_EX                                             ~12     ~12, ->20
         18    >   IS_SMALLER                                           ~13     !1, 0
         19        BOOL                                                 ~12     ~13
         20    > > JMPZ                                                         ~12, ->25
   21    21    >   NEW                                                  $14     'InvalidArgumentException'
         22        SEND_VAL_EX                                                  'Hours+must+be+between+0+and+23'
         23        DO_FCALL                                          0          
         24      > THROW                                             0          $14
   24    25    >   NEW                              self                $16     
         26        SEND_VAR_EX                                                  !1
         27        SEND_VAR_EX                                                  !2
         28        SEND_VAR_EX                                                  !3
         29        DO_FCALL                                          0          
         30        VERIFY_RETURN_TYPE                                           $16
         31      > RETURN                                                       $16
   25    32*       VERIFY_RETURN_TYPE                                           
         33*     > RETURN                                                       null

End of function frommysqltimeasdurationinday

Function todatetime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B6mr4
function name:  toDateTime
number of ops:  22
compiled vars:  !0 = $dateTime
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   27     0  E >   RECV_INIT                                            !0      null
   29     1        COALESCE                                             ~1      !0
          2        NEW                                                  $2      'DateTimeImmutable'
          3        DO_FCALL                                          0          
          4        ASSIGN                                               ~4      !0, $2
          5        QM_ASSIGN                                            ~1      ~4
          6        FREE                                                         ~1
   31     7        INIT_METHOD_CALL                                             !0, 'setTime'
          8        CHECK_FUNC_ARG                                               
          9        FETCH_OBJ_FUNC_ARG                                   $5      'hours'
         10        SEND_FUNC_ARG                                                $5
         11        CHECK_FUNC_ARG                                               
         12        FETCH_OBJ_FUNC_ARG                                   $6      'minutes'
         13        SEND_FUNC_ARG                                                $6
         14        CHECK_FUNC_ARG                                               
         15        FETCH_OBJ_FUNC_ARG                                   $7      'seconds'
         16        SEND_FUNC_ARG                                                $7
         17        DO_FCALL                                          0  $8      
         18        VERIFY_RETURN_TYPE                                           $8
         19      > RETURN                                                       $8
   32    20*       VERIFY_RETURN_TYPE                                           
         21*     > RETURN                                                       null

End of function todatetime

End of class MySqlTime.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.95 ms | 1395 KiB | 16 Q