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; public function __toString() { return "derp"; } } class BaseConfigWriter implements ConfigWriterInterface { public function write(BaseConfigValue $value) { echo "writing to {$value->storage_location}"; } } class ExampleGenerator { public function generate() { $value = new BaseConfigValue(); $value->storage_location = "/some/path/sample.config"; return $value; } } // Set up manager $manager = new WriteManager(); $manager->addWriter(new BaseConfigWriter, BaseConfigValue::class); $generator = new ExampleGenerator(); $value = $generator->generate(); $manager->write($value);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M9jR9
function name:  (null)
number of ops:  22
compiled vars:  !0 = $manager, !1 = $generator, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'configvalueinterface'
   35     1        DECLARE_CLASS                                            'baseconfigvalue'
   47     2        DECLARE_CLASS                                            'baseconfigwriter'
   70     3        NEW                                              $3      'WriteManager'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $3
   71     6        INIT_METHOD_CALL                                         !0, 'addWriter'
          7        NEW                                              $6      'BaseConfigWriter'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $6
         10        SEND_VAL_EX                                              'BaseConfigValue'
         11        DO_FCALL                                      0          
   74    12        NEW                                              $9      'ExampleGenerator'
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !1, $9
   75    15        INIT_METHOD_CALL                                         !1, 'generate'
         16        DO_FCALL                                      0  $12     
         17        ASSIGN                                                   !2, $12
   76    18        INIT_METHOD_CALL                                         !0, 'write'
         19        SEND_VAR_EX                                              !2
         20        DO_FCALL                                      0          
         21      > RETURN                                                   1

Class ConfigValueInterface:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M9jR9
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/M9jR9
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/M9jR9
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/M9jR9
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:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M9jR9
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E > > RETURN                                                   'derp'
   43     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function __tostring

End of class BaseConfigValue.

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

End of function write

End of class BaseConfigWriter.

Class ExampleGenerator:
Function generate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/M9jR9
function name:  generate
number of ops:  7
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   NEW                                              $1      'BaseConfigValue'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   63     3        ASSIGN_OBJ                                               !0, 'storage_location'
          4        OP_DATA                                                  '%2Fsome%2Fpath%2Fsample.config'
   65     5      > RETURN                                                   !0
   66     6*     > RETURN                                                   null

End of function generate

End of class ExampleGenerator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
186.47 ms | 1407 KiB | 13 Q