3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Roulette { public function move(); } interface Checkable { public function check(); } interface Rotatable { public function rotate(); } abstract class CircleLoad implements Rotatable, Checkable { protected $charges = null; public function __construct() { $this->setCharges(); } abstract protected function setCharges(); } class SixChargedRevolver extends CircleLoad { CONST CHARGES = 6; protected $loaded = null; protected $current = null; public function __construct() { $this->loaded = mt_rand(1, self::CHARGES); $this->current = 1; } public function check() { return $this->current==$this->loaded; } public function rotate() { $rotations = mt_rand(1, 2*self::CHARGES); $this->current = 1 + $rotations%self::CHARGES; } protected function setCharges() { $this->charges = self::CHARGES; } } abstract class RouletteGame implements Roulette { protected $playable = null; public function setPlayable(CircleLoad $playable) { $this->playable = $playable; } } class RussianRoulette extends RouletteGame { public function move() { $this->playable->rotate(); if($this->playable->check()) { die('Boom..'); } echo 'Click!'; } } class RussianRouletteFactory { public function create() { $playable = new SixChargedRevolver(); $roulette = new RussianRoulette(); $roulette->setPlayable($playable); return $roulette; } } $owner = new RussianRouletteFactory; $roulette = $owner->create(); $roulette->move(); $roulette->move(); $roulette->move(); $roulette->move();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tRTS8
function name:  (null)
number of ops:  19
compiled vars:  !0 = $owner, !1 = $roulette
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   DECLARE_CLASS                                            'circleload'
   30     1        DECLARE_CLASS                                            'sixchargedrevolver', 'circleload'
   59     2        DECLARE_CLASS                                            'roulettegame'
   68     3        DECLARE_CLASS                                            'russianroulette', 'roulettegame'
   92     4        NEW                                              $2      'RussianRouletteFactory'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   93     7        INIT_METHOD_CALL                                         !0, 'create'
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !1, $5
   94    10        INIT_METHOD_CALL                                         !1, 'move'
         11        DO_FCALL                                      0          
   95    12        INIT_METHOD_CALL                                         !1, 'move'
         13        DO_FCALL                                      0          
   96    14        INIT_METHOD_CALL                                         !1, 'move'
         15        DO_FCALL                                      0          
   97    16        INIT_METHOD_CALL                                         !1, 'move'
         17        DO_FCALL                                      0          
         18      > RETURN                                                   1

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

End of function move

End of class Roulette.

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

End of function check

End of class Checkable.

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

End of function rotate

End of class Rotatable.

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

End of function __construct

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

End of function setcharges

End of class CircleLoad.

Class SixChargedRevolver:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tRTS8
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   INIT_FCALL                                               'mt_rand'
          1        SEND_VAL                                                 1
          2        SEND_VAL                                                 6
          3        DO_ICALL                                         $1      
          4        ASSIGN_OBJ                                               'loaded'
          5        OP_DATA                                                  $1
   39     6        ASSIGN_OBJ                                               'current'
          7        OP_DATA                                                  1
   40     8      > RETURN                                                   null

End of function __construct

Function check:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tRTS8
function name:  check
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1        FETCH_OBJ_R                                      ~1      'loaded'
          2        IS_EQUAL                                         ~2      ~0, ~1
          3      > RETURN                                                   ~2
   45     4*     > RETURN                                                   null

End of function check

Function rotate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tRTS8
function name:  rotate
number of ops:  10
compiled vars:  !0 = $rotations
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   INIT_FCALL                                               'mt_rand'
          1        SEND_VAL                                                 1
          2        SEND_VAL                                                 12
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   50     5        MOD                                              ~4      !0, 6
          6        ADD                                              ~5      1, ~4
          7        ASSIGN_OBJ                                               'current'
          8        OP_DATA                                                  ~5
   51     9      > RETURN                                                   null

End of function rotate

Function setcharges:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tRTS8
function name:  setCharges
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   ASSIGN_OBJ                                               'charges'
          1        OP_DATA                                                  6
   56     2      > RETURN                                                   null

End of function setcharges

End of class SixChargedRevolver.

Class RouletteGame:
Function setplayable:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tRTS8
function name:  setPlayable
number of ops:  4
compiled vars:  !0 = $playable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   64     1        ASSIGN_OBJ                                               'playable'
          2        OP_DATA                                                  !0
   65     3      > RETURN                                                   null

End of function setplayable

End of class RouletteGame.

Class RussianRoulette:
Function move:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tRTS8
function name:  move
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   FETCH_OBJ_R                                      ~0      'playable'
          1        INIT_METHOD_CALL                                         ~0, 'rotate'
          2        DO_FCALL                                      0          
   73     3        FETCH_OBJ_R                                      ~2      'playable'
          4        INIT_METHOD_CALL                                         ~2, 'check'
          5        DO_FCALL                                      0  $3      
          6      > JMPZ                                                     $3, ->8
   75     7    > > EXIT                                                     'Boom..'
   77     8    >   ECHO                                                     'Click%21'
   78     9      > RETURN                                                   null

End of function move

End of class RussianRoulette.

Class RussianRouletteFactory:
Function create:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tRTS8
function name:  create
number of ops:  11
compiled vars:  !0 = $playable, !1 = $roulette
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   NEW                                              $2      'SixChargedRevolver'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   86     3        NEW                                              $5      'RussianRoulette'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   87     6        INIT_METHOD_CALL                                         !1, 'setPlayable'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   88     9      > RETURN                                                   !1
   89    10*     > RETURN                                                   null

End of function create

End of class RussianRouletteFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.98 ms | 1408 KiB | 15 Q