3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Translatable { interface Translatable {} } namespace Translatable\Impl { use Translatable\Translatable; class Translatable1 implements Translatable {} class Translatable2 implements Translatable {} class Translatable3 implements Translatable {} } namespace Translation { use Translatable\Translatable; interface Translator { public static function canTranslateBetween(Translatable $translatable1, Translatable $translatable2): bool; } class TranslatorFactory { /** @var string[] */ private $translatorClasses; public function __construct(array $translatorClasses) { $this->translatorClasses = $translatorClasses; } public function createTranslator(Translatable $a, Translatable $b): Translator { foreach ($this->translatorClasses as $translatorClass) { if ($translatorClass::canTranslateBetween($a, $b)) { return new $translatorClass; } } throw new \RuntimeException('Could not find translator.'); } } } namespace Translation\Impl { use Translatable\Impl\Translatable1; use Translatable\Impl\Translatable3; use Translatable\Translatable; use Translation\Translator; abstract class BaseTranslator implements Translator {} class Translator1 extends BaseTranslator { public static function canTranslateBetween(Translatable $translatable1, Translatable $translatable2): bool { return $translatable1 instanceof Translatable1 && $translatable2 instanceof Translatable3; } } class Translator2 extends BaseTranslator { public static function canTranslateBetween(Translatable $translatable1, Translatable $translatable2): bool { return false; } } class Translator3 extends BaseTranslator { public static function canTranslateBetween(Translatable $translatable1, Translatable $translatable2): bool { return false; } } } namespace { use Translatable\Impl\Translatable1; use Translatable\Impl\Translatable3; use Translation\Impl\Translator1; use Translation\Impl\Translator2; use Translation\Impl\Translator3; use Translation\TranslatorFactory; $translatorFactory = new TranslatorFactory([ Translator1::class, Translator2::class, Translator3::class ]); $translatable1 = new Translatable1(); $translatable3 = new Translatable3(); $translator = $translatorFactory->createTranslator($translatable1, $translatable3); var_dump($translator); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nfuB2
function name:  (null)
number of ops:  26
compiled vars:  !0 = $translatorFactory, !1 = $translatable1, !2 = $translatable3, !3 = $translator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_CLASS                                            'translatable%5Cimpl%5Ctranslatable1'
   10     1        DECLARE_CLASS                                            'translatable%5Cimpl%5Ctranslatable2'
   11     2        DECLARE_CLASS                                            'translatable%5Cimpl%5Ctranslatable3'
   49     3        DECLARE_CLASS                                            'translation%5Cimpl%5Cbasetranslator'
   51     4        DECLARE_CLASS                                            'translation%5Cimpl%5Ctranslator1', 'translation%5Cimpl%5Cbasetranslator'
   58     5        DECLARE_CLASS                                            'translation%5Cimpl%5Ctranslator2', 'translation%5Cimpl%5Cbasetranslator'
   65     6        DECLARE_CLASS                                            'translation%5Cimpl%5Ctranslator3', 'translation%5Cimpl%5Cbasetranslator'
   81     7        NEW                                              $4      'Translation%5CTranslatorFactory'
   82     8        SEND_VAL_EX                                              <array>
   81     9        DO_FCALL                                      0          
         10        ASSIGN                                                   !0, $4
   87    11        NEW                                              $7      'Translatable%5CImpl%5CTranslatable1'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !1, $7
   88    14        NEW                                              $10     'Translatable%5CImpl%5CTranslatable3'
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !2, $10
   89    17        INIT_METHOD_CALL                                         !0, 'createTranslator'
         18        SEND_VAR_EX                                              !1
         19        SEND_VAR_EX                                              !2
         20        DO_FCALL                                      0  $13     
         21        ASSIGN                                                   !3, $13
   91    22        INIT_FCALL                                               'var_dump'
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                                 
   92    25      > RETURN                                                   1

Class Translatable\Translatable: [no user functions]
Class Translatable\Impl\Translatable1: [no user functions]
Class Translatable\Impl\Translatable2: [no user functions]
Class Translatable\Impl\Translatable3: [no user functions]
Class Translation\Translator:
Function cantranslatebetween:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nfuB2
function name:  canTranslateBetween
number of ops:  4
compiled vars:  !0 = $translatable1, !1 = $translatable2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        VERIFY_RETURN_TYPE                                       
          3      > RETURN                                                   null

End of function cantranslatebetween

End of class Translation\Translator.

Class Translation\TranslatorFactory:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nfuB2
function name:  __construct
number of ops:  4
compiled vars:  !0 = $translatorClasses
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        ASSIGN_OBJ                                               'translatorClasses'
          2        OP_DATA                                                  !0
   29     3      > RETURN                                                   null

End of function __construct

Function createtranslator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 18
filename:       /in/nfuB2
function name:  createTranslator
number of ops:  25
compiled vars:  !0 = $a, !1 = $b, !2 = $translatorClass
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        FETCH_OBJ_R                                      ~3      'translatorClasses'
          3      > FE_RESET_R                                       $4      ~3, ->18
          4    > > FE_FETCH_R                                               $4, !2, ->18
   34     5    >   FETCH_CLASS                                   0  $5      !2
          6        INIT_STATIC_METHOD_CALL                                  $5, 'canTranslateBetween'
          7        SEND_VAR_EX                                              !0
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0  $6      
         10      > JMPZ                                                     $6, ->17
   35    11    >   FETCH_CLASS                                   0  $7      !2
         12        NEW                                              $8      $7
         13        DO_FCALL                                      0          
         14        VERIFY_RETURN_TYPE                                       $8
         15        FE_FREE                                                  $4
         16      > RETURN                                                   $8
   33    17    > > JMP                                                      ->4
         18    >   FE_FREE                                                  $4
   38    19        NEW                                              $10     'RuntimeException'
         20        SEND_VAL_EX                                              'Could+not+find+translator.'
         21        DO_FCALL                                      0          
         22      > THROW                                         0          $10
   39    23*       VERIFY_RETURN_TYPE                                       
         24*     > RETURN                                                   null

End of function createtranslator

End of class Translation\TranslatorFactory.

Class Translation\Impl\BaseTranslator: [no user functions]
Class Translation\Impl\Translator1:
Function cantranslatebetween:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/nfuB2
function name:  canTranslateBetween
number of ops:  10
compiled vars:  !0 = $translatable1, !1 = $translatable2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   54     2        INSTANCEOF                                       ~2      !0, 'Translatable%5CImpl%5CTranslatable1'
          3      > JMPZ_EX                                          ~2      ~2, ->6
          4    >   INSTANCEOF                                       ~3      !1, 'Translatable%5CImpl%5CTranslatable3'
          5        BOOL                                             ~2      ~3
          6    >   VERIFY_RETURN_TYPE                                       ~2
          7      > RETURN                                                   ~2
   55     8*       VERIFY_RETURN_TYPE                                       
          9*     > RETURN                                                   null

End of function cantranslatebetween

End of class Translation\Impl\Translator1.

Class Translation\Impl\Translator2:
Function cantranslatebetween:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nfuB2
function name:  canTranslateBetween
number of ops:  5
compiled vars:  !0 = $translatable1, !1 = $translatable2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   61     2      > RETURN                                                   <false>
   62     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function cantranslatebetween

End of class Translation\Impl\Translator2.

Class Translation\Impl\Translator3:
Function cantranslatebetween:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nfuB2
function name:  canTranslateBetween
number of ops:  5
compiled vars:  !0 = $translatable1, !1 = $translatable2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   68     2      > RETURN                                                   <false>
   69     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function cantranslatebetween

End of class Translation\Impl\Translator3.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.22 ms | 1019 KiB | 14 Q