3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Sleep { public static function for(Time $duration): void { usleep($duration->microseconds); } } readonly final class Time { public function __construct(public int $microseconds) { } public function add(self $time): self { return self::microseconds($this->microseconds + $time->microseconds); } public static function microseconds(int $duration): self { return new self($duration); } public static function milliseconds(int $duration): self { return new self($duration * 1000); } } function check(bool $a) { $sleep = Time::milliseconds(100); if ($a) { $sleep->add(Time::milliseconds(200)); } Sleep::for($sleep); echo 'CHECK:' . (new DateTime())->format(DateTimeInterface::ATOM); echo PHP_EOL; } echo 'OUTER_TIME: ' . (new DateTime())->format(DateTimeInterface::ATOM); echo PHP_EOL; check(false); echo 'OUTER_TIME: ' . (new DateTime())->format(DateTimeInterface::ATOM); echo PHP_EOL; check(true); echo 'OUTER_TIME: ' . (new DateTime())->format(DateTimeInterface::ATOM); echo PHP_EOL; // expected output: //OUTER_TIME: 2023-12-12T20:26:28+01:00 //Sleeping for 100 μseconds //CHECK:2023-12-12T20:26:28+01:00 // //OUTER_TIME: 2023-12-12T20:26:28+01:00 //Sleeping for 200 μseconds //CHECK:2023-12-12T20:26:28+01:00 // //OUTER_TIME: 2023-12-12T20:26:28+01:00
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhAXp
function name:  (null)
number of ops:  31
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   NEW                                              $0      'DateTime'
          1        DO_FCALL                                      0          
          2        INIT_METHOD_CALL                                         $0, 'format'
          3        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
          4        DO_FCALL                                      0  $2      
          5        CONCAT                                           ~3      'OUTER_TIME%3A+', $2
          6        ECHO                                                     ~3
   49     7        ECHO                                                     '%0A'
   50     8        INIT_FCALL                                               'check'
          9        SEND_VAL                                                 <false>
         10        DO_FCALL                                      0          
   51    11        NEW                                              $5      'DateTime'
         12        DO_FCALL                                      0          
         13        INIT_METHOD_CALL                                         $5, 'format'
         14        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         15        DO_FCALL                                      0  $7      
         16        CONCAT                                           ~8      'OUTER_TIME%3A+', $7
         17        ECHO                                                     ~8
   52    18        ECHO                                                     '%0A'
   53    19        INIT_FCALL                                               'check'
         20        SEND_VAL                                                 <true>
         21        DO_FCALL                                      0          
   54    22        NEW                                              $10     'DateTime'
         23        DO_FCALL                                      0          
         24        INIT_METHOD_CALL                                         $10, 'format'
         25        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         26        DO_FCALL                                      0  $12     
         27        CONCAT                                           ~13     'OUTER_TIME%3A+', $12
         28        ECHO                                                     ~13
   55    29        ECHO                                                     '%0A'
   66    30      > RETURN                                                   1

Function check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/WhAXp
function name:  check
number of ops:  24
compiled vars:  !0 = $a, !1 = $sleep
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        INIT_STATIC_METHOD_CALL                                  'Time', 'milliseconds'
          2        SEND_VAL                                                 100
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !1, $2
   38     5      > JMPZ                                                     !0, ->12
   39     6    >   INIT_METHOD_CALL                                         !1, 'add'
          7        INIT_STATIC_METHOD_CALL                                  'Time', 'milliseconds'
          8        SEND_VAL                                                 200
          9        DO_FCALL                                      0  $4      
         10        SEND_VAR_NO_REF_EX                                       $4
         11        DO_FCALL                                      0          
   42    12    >   INIT_STATIC_METHOD_CALL                                  'Sleep', 'for'
         13        SEND_VAR                                                 !1
         14        DO_FCALL                                      0          
   44    15        NEW                                              $7      'DateTime'
         16        DO_FCALL                                      0          
         17        INIT_METHOD_CALL                                         $7, 'format'
         18        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         19        DO_FCALL                                      0  $9      
         20        CONCAT                                           ~10     'CHECK%3A', $9
         21        ECHO                                                     ~10
   45    22        ECHO                                                     '%0A'
   46    23      > RETURN                                                   null

End of function check

Class Sleep:
Function for:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhAXp
function name:  for
number of ops:  6
compiled vars:  !0 = $duration
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        INIT_FCALL                                               'usleep'
          2        FETCH_OBJ_R                                      ~1      !0, 'microseconds'
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                                 
    8     5      > RETURN                                                   null

End of function for

End of class Sleep.

Class Time:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhAXp
function name:  __construct
number of ops:  4
compiled vars:  !0 = $microseconds
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'microseconds'
          2        OP_DATA                                                  !0
   15     3      > RETURN                                                   null

End of function __construct

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhAXp
function name:  add
number of ops:  11
compiled vars:  !0 = $time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        INIT_STATIC_METHOD_CALL                                  'microseconds'
          2        FETCH_OBJ_R                                      ~1      'microseconds'
          3        FETCH_OBJ_R                                      ~2      !0, 'microseconds'
          4        ADD                                              ~3      ~1, ~2
          5        SEND_VAL_EX                                              ~3
          6        DO_FCALL                                      0  $4      
          7        VERIFY_RETURN_TYPE                                       $4
          8      > RETURN                                                   $4
   20     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function add

Function microseconds:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhAXp
function name:  microseconds
number of ops:  8
compiled vars:  !0 = $duration
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        NEW                          self                $1      
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   25     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function microseconds

Function milliseconds:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WhAXp
function name:  milliseconds
number of ops:  9
compiled vars:  !0 = $duration
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        NEW                          self                $1      
          2        MUL                                              ~2      !0, 1000
          3        SEND_VAL_EX                                              ~2
          4        DO_FCALL                                      0          
          5        VERIFY_RETURN_TYPE                                       $1
          6      > RETURN                                                   $1
   30     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function milliseconds

End of class Time.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.27 ms | 1009 KiB | 16 Q