3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private const string PREFIX = "Hello. "; private static string $prefix = "Hello, "; private function prefix(): string { return "Hello, "; } public function greetFunc(string $to): string { return static::prefix() . $to . "!"; // OK, but unnecessary LSB } public function greetVar(string $to): string { return static::$prefix . $to . "!"; // OK, but unnecessary LSB } public function greetConst(string $to): string { return static::PREFIX . $to . "!"; // It should be self::PREFIX. } } class Bar extends Foo { } class Buz extends Foo { private static string $prefix = "Hi, "; private function prefix(): string { return "Hi, "; } } echo (new Bar())->greetFunc("World") . PHP_EOL; echo (new Bar())->greetVar("World") . PHP_EOL; // echo (new Bar())->greetConst("World") . PHP_EOL; // Referencing undefined Bar::PREFIX... // echo (new Buz())->greetFunc("World") . PHP_EOL; // Referencing private Buz::prefix() from Foo class // echo (new Buz())->greetVar("World") . PHP_EOL; // Referencing private Buz::$prefix from Foo class
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   NEW                                              $0      'Bar'
          1        DO_FCALL                                      0          
          2        INIT_METHOD_CALL                                         $0, 'greetFunc'
          3        SEND_VAL_EX                                              'World'
          4        DO_FCALL                                      0  $2      
          5        CONCAT                                           ~3      $2, '%0A'
          6        ECHO                                                     ~3
   45     7        NEW                                              $4      'Bar'
          8        DO_FCALL                                      0          
          9        INIT_METHOD_CALL                                         $4, 'greetVar'
         10        SEND_VAL_EX                                              'World'
         11        DO_FCALL                                      0  $6      
         12        CONCAT                                           ~7      $6, '%0A'
         13        ECHO                                                     ~7
   49    14      > RETURN                                                   1

Class Foo:
Function prefix:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  prefix
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E > > RETURN                                                   'Hello%2C+'
   12     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function prefix

Function greetfunc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  greetFunc
number of ops:  9
compiled vars:  !0 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        INIT_STATIC_METHOD_CALL                                  'prefix'
          2        DO_FCALL                                      0  $1      
          3        CONCAT                                           ~2      $1, !0
          4        CONCAT                                           ~3      ~2, '%21'
          5        VERIFY_RETURN_TYPE                                       ~3
          6      > RETURN                                                   ~3
   17     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function greetfunc

Function greetvar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  greetVar
number of ops:  8
compiled vars:  !0 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        FETCH_STATIC_PROP_R          unknown             ~1      'prefix'
          2        CONCAT                                           ~2      ~1, !0
          3        CONCAT                                           ~3      ~2, '%21'
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   22     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function greetvar

Function greetconst:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  greetConst
number of ops:  8
compiled vars:  !0 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        FETCH_CLASS_CONSTANT                             ~1      'PREFIX'
          2        CONCAT                                           ~2      ~1, !0
          3        CONCAT                                           ~3      ~2, '%21'
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   27     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function greetconst

End of class Foo.

Class Bar:
Function prefix:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  prefix
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E > > RETURN                                                   'Hello%2C+'
   12     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function prefix

Function greetfunc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  greetFunc
number of ops:  9
compiled vars:  !0 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        INIT_STATIC_METHOD_CALL                                  'prefix'
          2        DO_FCALL                                      0  $1      
          3        CONCAT                                           ~2      $1, !0
          4        CONCAT                                           ~3      ~2, '%21'
          5        VERIFY_RETURN_TYPE                                       ~3
          6      > RETURN                                                   ~3
   17     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function greetfunc

Function greetvar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  greetVar
number of ops:  8
compiled vars:  !0 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        FETCH_STATIC_PROP_R          unknown             ~1      'prefix'
          2        CONCAT                                           ~2      ~1, !0
          3        CONCAT                                           ~3      ~2, '%21'
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   22     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function greetvar

Function greetconst:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  greetConst
number of ops:  8
compiled vars:  !0 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        FETCH_CLASS_CONSTANT                             ~1      'PREFIX'
          2        CONCAT                                           ~2      ~1, !0
          3        CONCAT                                           ~3      ~2, '%21'
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   27     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function greetconst

End of class Bar.

Class Buz:
Function prefix:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  prefix
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E > > RETURN                                                   'Hi%2C+'
   41     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function prefix

Function greetfunc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  greetFunc
number of ops:  9
compiled vars:  !0 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        INIT_STATIC_METHOD_CALL                                  'prefix'
          2        DO_FCALL                                      0  $1      
          3        CONCAT                                           ~2      $1, !0
          4        CONCAT                                           ~3      ~2, '%21'
          5        VERIFY_RETURN_TYPE                                       ~3
          6      > RETURN                                                   ~3
   17     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function greetfunc

Function greetvar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  greetVar
number of ops:  8
compiled vars:  !0 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        FETCH_STATIC_PROP_R          unknown             ~1      'prefix'
          2        CONCAT                                           ~2      ~1, !0
          3        CONCAT                                           ~3      ~2, '%21'
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   22     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function greetvar

Function greetconst:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kmct0
function name:  greetConst
number of ops:  8
compiled vars:  !0 = $to
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        FETCH_CLASS_CONSTANT                             ~1      'PREFIX'
          2        CONCAT                                           ~2      ~1, !0
          3        CONCAT                                           ~3      ~2, '%21'
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   27     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function greetconst

End of class Buz.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.38 ms | 1026 KiB | 13 Q