3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param int|float|string $timestamp */ function createDateTimeImmutableFromTimestamp($timestamp): \DateTimeImmutable { if (\is_string($timestamp)) { $timestamp = \ctype_digit($timestamp) ? (int)$timestamp : (float)$timestamp; } $secs = (int)$timestamp; $usecs = \is_float($timestamp) ? (int)(1000000 * ($timestamp - $secs)) : 0; return \DateTimeImmutable::createFromFormat('U u', \sprintf('%d %06d', $secs, $usecs)); } $tests = [time(), microtime(true), 1234567890.123, '1.12345678901e9']; foreach ($tests as $test) { echo "{$test}: " . createDateTimeImmutableFromTimestamp($test)->format('Y-m-d H:i:s.u') . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 24
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/XZiG0
function name:  (null)
number of ops:  26
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'time'
          1        DO_ICALL                                         $2      
          2        INIT_ARRAY                                       ~3      $2
          3        INIT_FCALL                                               'microtime'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $4      
          6        ADD_ARRAY_ELEMENT                                ~3      $4
          7        ADD_ARRAY_ELEMENT                                ~3      1.23457e+9
          8        ADD_ARRAY_ELEMENT                                ~3      '1.12345678901e9'
          9        ASSIGN                                                   !0, ~3
   24    10      > FE_RESET_R                                       $6      !0, ->24
         11    > > FE_FETCH_R                                               $6, !1, ->24
   25    12    >   NOP                                                      
         13        FAST_CONCAT                                      ~7      !1, '%3A+'
         14        INIT_FCALL                                               'createdatetimeimmutablefromtimestamp'
         15        SEND_VAR                                                 !1
         16        DO_FCALL                                      0  $8      
         17        INIT_METHOD_CALL                                         $8, 'format'
         18        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As.u'
         19        DO_FCALL                                      0  $9      
         20        CONCAT                                           ~10     ~7, $9
         21        CONCAT                                           ~11     ~10, '%0A'
         22        ECHO                                                     ~11
   24    23      > JMP                                                      ->11
         24    >   FE_FREE                                                  $6
   26    25      > RETURN                                                   1

Function createdatetimeimmutablefromtimestamp:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
Branch analysis from position: 22
Branch analysis from position: 13
filename:       /in/XZiG0
function name:  createDateTimeImmutableFromTimestamp
number of ops:  37
compiled vars:  !0 = $timestamp, !1 = $secs, !2 = $usecs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        TYPE_CHECK                                   64          !0
          2      > JMPZ                                                     ~3, ->13
    9     3    >   INIT_FCALL                                               'ctype_digit'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $4      
          6      > JMPZ                                                     $4, ->10
   10     7    >   CAST                                          4  ~5      !0
          8        QM_ASSIGN                                        ~6      ~5
          9      > JMP                                                      ->12
   11    10    >   CAST                                          5  ~7      !0
         11        QM_ASSIGN                                        ~6      ~7
    9    12    >   ASSIGN                                                   !0, ~6
   14    13    >   CAST                                          4  ~9      !0
         14        ASSIGN                                                   !1, ~9
   15    15        TYPE_CHECK                                   32          !0
         16      > JMPZ                                                     ~11, ->22
   16    17    >   SUB                                              ~12     !0, !1
         18        MUL                                              ~13     ~12, 1000000
         19        CAST                                          4  ~14     ~13
         20        QM_ASSIGN                                        ~15     ~14
         21      > JMP                                                      ->23
   17    22    >   QM_ASSIGN                                        ~15     0
   15    23    >   ASSIGN                                                   !2, ~15
   19    24        INIT_STATIC_METHOD_CALL                                  'DateTimeImmutable', 'createFromFormat'
         25        SEND_VAL                                                 'U+u'
         26        INIT_FCALL                                               'sprintf'
         27        SEND_VAL                                                 '%25d+%2506d'
         28        SEND_VAR                                                 !1
         29        SEND_VAR                                                 !2
         30        DO_ICALL                                         $17     
         31        SEND_VAR                                                 $17
         32        DO_FCALL                                      0  $18     
         33        VERIFY_RETURN_TYPE                                       $18
         34      > RETURN                                                   $18
   20    35*       VERIFY_RETURN_TYPE                                       
         36*     > RETURN                                                   null

End of function createdatetimeimmutablefromtimestamp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
133.3 ms | 1407 KiB | 22 Q