3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface TemporaryFile { public function handle(\Closure $closure) : void; public function write(string $contents): void; public function getContents() : string; public function chmod(int $mode): void; public function getUri() : string; // aka realpath public function close() : void; } class IO { /** * @return TemporaryFile */ public static function getTemporaryFile() : TemporaryFile { return new class implements TemporaryFile { private $handle; public function __construct() { $this->handle = tmpfile(); } public function handle(\Closure $closure) : void { $closure($this->handle); } public function getContents() : string { // according to PHP docs file_get_contents has much better performance // http://php.net/manual/en/function.fread.php return file_get_contents($this->getUri()); } public function getUri() : string { return stream_get_meta_data($this->handle)['uri']; } public function close() : void { if (is_resource($this->handle)) fclose($this->handle); } public function write(string $contents): void { fwrite($this->handle, $contents); } public function chmod(int $mode): void { chmod($this->getUri(), $mode); } public function __destruct() { $this->close(); } }; } } $file = IO::getTemporaryFile(); $file->write('foo'); var_dump($file->getContents());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  (null)
number of ops:  12
compiled vars:  !0 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_STATIC_METHOD_CALL                                  'IO', 'getTemporaryFile'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   63     3        INIT_METHOD_CALL                                         !0, 'write'
          4        SEND_VAL_EX                                              'foo'
          5        DO_FCALL                                      0          
   64     6        INIT_FCALL                                               'var_dump'
          7        INIT_METHOD_CALL                                         !0, 'getContents'
          8        DO_FCALL                                      0  $4      
          9        SEND_VAR                                                 $4
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Class TemporaryFile:
Function handle:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  handle
number of ops:  2
compiled vars:  !0 = $closure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function handle

Function write:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  write
number of ops:  2
compiled vars:  !0 = $contents
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function write

Function getcontents:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  getContents
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   VERIFY_RETURN_TYPE                                       
          1      > RETURN                                                   null

End of function getcontents

Function chmod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  chmod
number of ops:  2
compiled vars:  !0 = $mode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function chmod

Function geturi:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  getUri
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   VERIFY_RETURN_TYPE                                       
          1      > RETURN                                                   null

End of function geturi

Function close:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  close
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E > > RETURN                                                   null

End of function close

End of class TemporaryFile.

Class TemporaryFile@anonymous:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'tmpfile'
          1        DO_ICALL                                         $1      
          2        ASSIGN_OBJ                                               'handle'
          3        OP_DATA                                                  $1
   24     4      > RETURN                                                   null

End of function __construct

Function handle:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  handle
number of ops:  7
compiled vars:  !0 = $closure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        INIT_DYNAMIC_CALL                                        !0
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'handle'
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0          
   28     6      > RETURN                                                   null

End of function handle

Function getcontents:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  getContents
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                               'file_get_contents'
          1        INIT_METHOD_CALL                                         'getUri'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        DO_ICALL                                         $1      
          5        VERIFY_RETURN_TYPE                                       $1
          6      > RETURN                                                   $1
   34     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function getcontents

Function geturi:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  getUri
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'stream_get_meta_data'
          1        FETCH_OBJ_R                                      ~0      'handle'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        FETCH_DIM_R                                      ~2      $1, 'uri'
          5        VERIFY_RETURN_TYPE                                       ~2
          6      > RETURN                                                   ~2
   38     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function geturi

Function close:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/LYfan
function name:  close
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   FETCH_OBJ_R                                      ~0      'handle'
          1        TYPE_CHECK                                  512          ~0
          2      > JMPZ                                                     ~1, ->7
   42     3    >   INIT_FCALL                                               'fclose'
          4        FETCH_OBJ_R                                      ~2      'handle'
          5        SEND_VAL                                                 ~2
          6        DO_ICALL                                                 
   43     7    > > RETURN                                                   null

End of function close

Function write:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  write
number of ops:  7
compiled vars:  !0 = $contents
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1        INIT_FCALL                                               'fwrite'
          2        FETCH_OBJ_R                                      ~1      'handle'
          3        SEND_VAL                                                 ~1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   48     6      > RETURN                                                   null

End of function write

Function chmod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  chmod
number of ops:  8
compiled vars:  !0 = $mode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   52     1        INIT_FCALL                                               'chmod'
          2        INIT_METHOD_CALL                                         'getUri'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR                                                 $1
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
   53     7      > RETURN                                                   null

End of function chmod

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  __destruct
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   INIT_METHOD_CALL                                         'close'
          1        DO_FCALL                                      0          
   57     2      > RETURN                                                   null

End of function __destruct

End of class TemporaryFile@anonymous.

Class IO:
Function gettemporaryfile:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LYfan
function name:  getTemporaryFile
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   DECLARE_ANON_CLASS                               <unknown> 
          1        NEW                                              $1      $0
          2        DO_FCALL                                      0          
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
   59     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function gettemporaryfile

End of class IO.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.75 ms | 1017 KiB | 20 Q