3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Sleep { protected ?int $pending = null; public function __construct(int $duration) { $this->pending = $duration; } public static function for(int $duration): static { return new static($duration); } public function one(): static { $this->pending = 100; return $this; } public function two(): static { $this->pending = 200; return $this; } public function __destruct() { if ($this->pending > 0) { echo 'Sleeping for ' . $this->pending . ' μseconds' . PHP_EOL; echo PHP_EOL; usleep($this->pending); } } } function check(bool $a) { $sleep = (new Sleep(2))->one(); if ($a) { $sleep->two(); } // author expecting two seconds or one minute to be slept before calling next line: 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/ADnGA
function name:  (null)
number of ops:  31
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     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
   54     7        ECHO                                                     '%0A'
   55     8        INIT_FCALL                                               'check'
          9        SEND_VAL                                                 <false>
         10        DO_FCALL                                      0          
   56    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
   57    18        ECHO                                                     '%0A'
   58    19        INIT_FCALL                                               'check'
         20        SEND_VAL                                                 <true>
         21        DO_FCALL                                      0          
   59    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
   60    29        ECHO                                                     '%0A'
   71    30      > RETURN                                                   1

Function check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/ADnGA
function name:  check
number of ops:  19
compiled vars:  !0 = $a, !1 = $sleep
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        NEW                                              $2      'Sleep'
          2        SEND_VAL_EX                                              2
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $2, 'one'
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   44     7      > JMPZ                                                     !0, ->10
   45     8    >   INIT_METHOD_CALL                                         !1, 'two'
          9        DO_FCALL                                      0          
   49    10    >   NEW                                              $7      'DateTime'
         11        DO_FCALL                                      0          
         12        INIT_METHOD_CALL                                         $7, 'format'
         13        SEND_VAL_EX                                              'Y-m-d%5CTH%3Ai%3AsP'
         14        DO_FCALL                                      0  $9      
         15        CONCAT                                           ~10     'CHECK%3A', $9
         16        ECHO                                                     ~10
   50    17        ECHO                                                     '%0A'
   51    18      > RETURN                                                   null

End of function check

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

End of function __construct

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

End of function for

Function one:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ADnGA
function name:  one
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN_OBJ                                               'pending'
          1        OP_DATA                                                  100
   21     2        FETCH_THIS                                       ~1      
          3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   22     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function one

Function two:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ADnGA
function name:  two
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN_OBJ                                               'pending'
          1        OP_DATA                                                  200
   28     2        FETCH_THIS                                       ~1      
          3        VERIFY_RETURN_TYPE                                       ~1
          4      > RETURN                                                   ~1
   29     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function two

Function __destruct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/ADnGA
function name:  __destruct
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   FETCH_OBJ_R                                      ~0      'pending'
          1        IS_SMALLER                                               0, ~0
          2      > JMPZ                                                     ~1, ->13
   34     3    >   FETCH_OBJ_R                                      ~2      'pending'
          4        CONCAT                                           ~3      'Sleeping+for+', ~2
          5        CONCAT                                           ~4      ~3, '+%CE%BCseconds'
          6        CONCAT                                           ~5      ~4, '%0A'
          7        ECHO                                                     ~5
   35     8        ECHO                                                     '%0A'
   36     9        INIT_FCALL                                               'usleep'
         10        FETCH_OBJ_R                                      ~6      'pending'
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                                 
   38    13    > > RETURN                                                   null

End of function __destruct

End of class Sleep.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.12 ms | 1009 KiB | 16 Q