3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function __toString() : string { return 'bar'; } } echo (new Foo())->__toString(), PHP_EOL, (new Foo())->__toString()[2], PHP_EOL, (new Foo()), PHP_EOL, ((string)(new Foo()))[2];
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K255i
function name:  (null)
number of ops:  24
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'foo'
   11     1        NEW                                              $0      'Foo'
          2        DO_FCALL                                      0          
          3        INIT_METHOD_CALL                                         $0, '__toString'
          4        DO_FCALL                                      0  $2      
          5        ECHO                                                     $2
          6        ECHO                                                     '%0A'
   12     7        NEW                                              $3      'Foo'
          8        DO_FCALL                                      0          
          9        INIT_METHOD_CALL                                         $3, '__toString'
         10        DO_FCALL                                      0  $5      
         11        FETCH_DIM_R                                      ~6      $5, 2
         12        ECHO                                                     ~6
         13        ECHO                                                     '%0A'
   13    14        NEW                                              $7      'Foo'
         15        DO_FCALL                                      0          
         16        ECHO                                                     $7
         17        ECHO                                                     '%0A'
   14    18        NEW                                              $9      'Foo'
         19        DO_FCALL                                      0          
         20        CAST                                          6  ~11     $9
         21        FETCH_DIM_R                                      ~12     ~11, 2
         22        ECHO                                                     ~12
         23      > RETURN                                                   1

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

End of function __tostring

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.52 ms | 999 KiB | 13 Q