3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class almostSingleton { final protected function __construct() { echo 'Built ' . get_class($this) . PHP_EOL; } } class GoodTwin extends almostSingleton { } class EvilTwin extends almostSingleton { public static function static_getGoodTwin() { return new GoodTwin(); } public function getGoodTwin() { return new GoodTwin(); } } $gotcha = EvilTwin::static_getGoodTwin(); $et = new EvilTwin(); $nope = $et->getGoodTwin();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/glRkc
function name:  (null)
number of ops:  10
compiled vars:  !0 = $gotcha, !1 = $et, !2 = $nope
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_STATIC_METHOD_CALL                                  'EvilTwin', 'static_getGoodTwin'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   22     3        NEW                                              $5      'EvilTwin'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   23     6        INIT_METHOD_CALL                                         !1, 'getGoodTwin'
          7        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !2, $8
          9      > RETURN                                                   1

Class almostSingleton:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/glRkc
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   FETCH_THIS                                       ~0      
          1        GET_CLASS                                        ~1      ~0
          2        CONCAT                                           ~2      'Built+', ~1
          3        CONCAT                                           ~3      ~2, '%0A'
          4        ECHO                                                     ~3
    6     5      > RETURN                                                   null

End of function __construct

End of class almostSingleton.

Class GoodTwin:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/glRkc
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   FETCH_THIS                                       ~0      
          1        GET_CLASS                                        ~1      ~0
          2        CONCAT                                           ~2      'Built+', ~1
          3        CONCAT                                           ~3      ~2, '%0A'
          4        ECHO                                                     ~3
    6     5      > RETURN                                                   null

End of function __construct

End of class GoodTwin.

Class EvilTwin:
Function static_getgoodtwin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/glRkc
function name:  static_getGoodTwin
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   NEW                                              $0      'GoodTwin'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   15     3*     > RETURN                                                   null

End of function static_getgoodtwin

Function getgoodtwin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/glRkc
function name:  getGoodTwin
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $0      'GoodTwin'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   18     3*     > RETURN                                                   null

End of function getgoodtwin

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/glRkc
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   FETCH_THIS                                       ~0      
          1        GET_CLASS                                        ~1      ~0
          2        CONCAT                                           ~2      'Built+', ~1
          3        CONCAT                                           ~3      ~2, '%0A'
          4        ECHO                                                     ~3
    6     5      > RETURN                                                   null

End of function __construct

End of class EvilTwin.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
125.68 ms | 1403 KiB | 13 Q