3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ConfigValueInterface { public function __toString(); } interface ConfigWriterInterface { public function write(ConfigValueInterface $value); } class WriteManager { protected $writers = []; public function addWriter(ConfigWriterInterface $writer, $value_class) { $this->writers[$value_class] = $writer; } public function write(ConfigValueInterface $value) { $class = get_class($value); if (isset($this->writers[$class])) { $this->writers[$class]->write($value); } } } class BaseConfigValue implements ConfigValueInterface { public $storage_location; } class BaseConfigWriter implements ConfigWriterInterface { public function write(BaseConfigValue $value) { echo "writing to {$value->storage_location}"; } } // Set up manager $manager = new WriteManager(); $manager->addWriter(new BaseConfigWriter, BaseConfigValue::class); // $value = $generator->generate(); $manager->write($value);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RpMVW
function name:  (null)
number of ops:  16
compiled vars:  !0 = $manager, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'configvalueinterface'
   35     1        DECLARE_CLASS                                            'baseconfigvalue'
   42     2        DECLARE_CLASS                                            'baseconfigwriter'
   53     3        NEW                                              $2      'WriteManager'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
   54     6        INIT_METHOD_CALL                                         !0, 'addWriter'
          7        NEW                                              $5      'BaseConfigWriter'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $5
         10        SEND_VAL_EX                                              'BaseConfigValue'
         11        DO_FCALL                                      0          
   57    12        INIT_METHOD_CALL                                         !0, 'write'
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0          
         15      > RETURN                                                   1

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

End of function __tostring

End of class ConfigValueInterface.

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

End of function write

End of class ConfigWriterInterface.

Class WriteManager:
Function addwriter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RpMVW
function name:  addWriter
number of ops:  6
compiled vars:  !0 = $writer, !1 = $value_class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        FETCH_OBJ_W                                      $2      'writers'
          3        ASSIGN_DIM                                               $2, !1
          4        OP_DATA                                                  !0
   23     5      > RETURN                                                   null

End of function addwriter

Function write:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/RpMVW
function name:  write
number of ops:  12
compiled vars:  !0 = $value, !1 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        GET_CLASS                                        ~2      !0
          2        ASSIGN                                                   !1, ~2
   28     3        FETCH_OBJ_IS                                     ~4      'writers'
          4        ISSET_ISEMPTY_DIM_OBJ                         0          ~4, !1
          5      > JMPZ                                                     ~5, ->11
   29     6    >   FETCH_OBJ_R                                      ~6      'writers'
          7        FETCH_DIM_R                                      ~7      ~6, !1
          8        INIT_METHOD_CALL                                         ~7, 'write'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
   31    11    > > RETURN                                                   null

End of function write

End of class WriteManager.

Class BaseConfigValue: [no user functions]
Class BaseConfigWriter:
Function write:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RpMVW
function name:  write
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1        NOP                                                      
          2        FETCH_OBJ_R                                      ~1      !0, 'storage_location'
          3        FAST_CONCAT                                      ~2      'writing+to+', ~1
          4        ECHO                                                     ~2
   48     5      > RETURN                                                   null

End of function write

End of class BaseConfigWriter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.49 ms | 1399 KiB | 13 Q