3v4l.org

run code in 300+ PHP versions simultaneously
<?php class AssemblyFactory { public const PUMPMETHODS = [ 'modelNumber' => 'fromModelNumber', 'productId' => 'fromProductId' ]; public $pumpFactory; public function __construct () { $this->pumpFactory = new PumpFactory(); } public function makeAssembly(array $params) { $validMethods = array_intersect_key(self::PUMPMETHODS, $params); if (!$validMethods) { throw new \InvalidArgumentException("FAIL"); } else { foreach ($validMethods as $paramKey => $methodName) { return $this->pumpFactory->{$methodName}($params[$paramKey]); } } } } class PumpFactory { public function fromProductId($id) { return "__{$id}__"; } public function fromModelNumber($id) { return "**{$id}**"; } } $factory = new AssemblyFactory(); $tests = [ ['productId' => 33], ['modelNumber' => 'AAA-50'], ['productId' => 1, 'modelNumber' => 'BBB-01'], ['invalidKey' => 'nope'] ]; foreach ($tests as $testParams) { $factory = new AssemblyFactory; echo "Pump = " , $factory->makeAssembly($testParams), "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/C6h1o
function name:  (null)
number of ops:  18
compiled vars:  !0 = $factory, !1 = $tests, !2 = $testParams
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  39     0  E >   NEW                                              $3      :31
         1        DO_FCALL                                      0          
         2        QM_ASSIGN                                                !0
  42     3        QM_ASSIGN                                                !1
  48     4      > FE_RESET_R                                       $7      !1, ->16
         5    > > FE_FETCH_R                                               $7, !2, ->16
  49     6    >   NEW                                              $8      :22
         7        DO_FCALL                                      0          
         8        QM_ASSIGN                                                !0
  50     9        ASSIGN_OBJ                                               'Pump+%3D+'
        10        INIT_METHOD_CALL                                         !0, 'makeAssembly'
        11        SEND_VAR_EX                                              !2
        12        DO_FCALL                                      0  $11     
        13        ASSIGN_OBJ                                               $11
        14        ASSIGN_OBJ                                               '%0A'
  48    15      > JMP                                                      ->5
        16    >   FE_FREE                                                  $7
  51    17      > RETURN                                                   1

Class AssemblyFactory:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C6h1o
function name:  __construct
number of ops:  5
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  12     0  E >   NEW                                              $1      :6
         1        DO_FCALL                                      0          
         2        ASSIGN_SUB                                    0          'pumpFactory'
         3        OP_DATA                                                  $1
  13     4      > RETURN                                                   null

End of function __construct

Function makeassembly:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/C6h1o
function name:  makeAssembly
number of ops:  27
compiled vars:  !0 = $params, !1 = $validMethods, !2 = $methodName, !3 = $paramKey
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  15     0  E >   RECV                                             !0      
  16     1        INIT_FCALL                                               'array_intersect_key'
         2        SEND_VAL                                                 <array>
         3        SEND_VAR                                                 !0
         4        DO_ICALL                                         $4      
         5        QM_ASSIGN                                                !1
  17     6        BOOL_XOR                                         ~6      !1
         7      > JMPZ                                                     ~6, ->13
  18     8    >   NEW                                              $7      :35
         9        SEND_VAL_EX                                              'FAIL'
        10        DO_FCALL                                      0          
        11      > THROW                                         0          $7
        12*       JMP                                                      ->26
  20    13    > > FE_RESET_R                                       $9      !1, ->25
        14    > > FE_FETCH_R                                       ~10     $9, !2, ->25
        15    >   QM_ASSIGN                                                !3
  21    16        FETCH_OBJ_R                                      ~12     'pumpFactory'
        17        INIT_METHOD_CALL                                         ~12, !2
        18        CHECK_FUNC_ARG                                           
        19        FETCH_DIM_FUNC_ARG                               $13     !0, !3
        20        SEND_FUNC_ARG                                            $13
        21        DO_FCALL                                      0  $14     
        22        FE_FREE                                                  $9
        23      > RETURN                                                   $14
  20    24*       JMP                                                      ->14
        25    >   FE_FREE                                                  $9
  24    26      > RETURN                                                   null

End of function makeassembly

End of class AssemblyFactory.

Class PumpFactory:
Function fromproductid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C6h1o
function name:  fromProductId
number of ops:  6
compiled vars:  !0 = $id
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  29     0  E >   RECV                                             !0      
  30     1        ROPE_INIT                                     3  ~2      '__'
         2        ROPE_ADD                                      1  ~2      ~2, !0
         3        ROPE_END                                      2  ~1      ~2, '__'
         4      > RETURN                                                   ~1
  31     5*     > RETURN                                                   null

End of function fromproductid

Function frommodelnumber:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C6h1o
function name:  fromModelNumber
number of ops:  6
compiled vars:  !0 = $id
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  33     0  E >   RECV                                             !0      
  34     1        ROPE_INIT                                     3  ~2      '%2A%2A'
         2        ROPE_ADD                                      1  ~2      ~2, !0
         3        ROPE_END                                      2  ~1      ~2, '%2A%2A'
         4      > RETURN                                                   ~1
  35     5*     > RETURN                                                   null

End of function frommodelnumber

End of class PumpFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
13.52 ms | 467 KiB | 7 Q