3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Project\Model\Entity; /** * Class EntityFactory * * A factory to DI around to build entities * * @package Project\Model\Entity */ class EntityFactory { /** * Create your entity * * @param string $entityName This should be the concrete name of the entity, like 'User' or 'Test' * @param array $args Single dimensional array of required entity arguments * * @return object The entity - you will have to typehint the object in your code for IDE auto-completion */ public function buildEntity($entityName, array $args = []) { if (!class_exists($className = sprintf('%s\%s', __NAMESPACE__, $entityName))) { throw new \InvalidArgumentException(sprintf( 'Invalid entity name provided, got: %s', $entityName )); } $reflector = new \ReflectionClass($className); return $reflector->newInstanceArgs($args); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8O4NW
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E > > RETURN                                                   1

Class Project\Model\Entity\EntityFactory:
Function buildentity:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8O4NW
function name:  buildEntity
number of ops:  30
compiled vars:  !0 = $entityName, !1 = $args, !2 = $className, !3 = $reflector
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   24     2        INIT_NS_FCALL_BY_NAME                                    'Project%5CModel%5CEntity%5Cclass_exists'
          3        INIT_NS_FCALL_BY_NAME                                    'Project%5CModel%5CEntity%5Csprintf'
          4        SEND_VAL_EX                                              '%25s%5C%25s'
          5        SEND_VAL_EX                                              'Project%5CModel%5CEntity'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                           ~5      !2, $4
          9        SEND_VAL_EX                                              ~5
         10        DO_FCALL                                      0  $6      
         11        BOOL_NOT                                         ~7      $6
         12      > JMPZ                                                     ~7, ->21
   26    13    >   NEW                                              $8      'InvalidArgumentException'
         14        INIT_NS_FCALL_BY_NAME                                    'Project%5CModel%5CEntity%5Csprintf'
   27    15        SEND_VAL_EX                                              'Invalid+entity+name+provided%2C+got%3A+%25s'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $9      
         18        SEND_VAR_NO_REF_EX                                       $9
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $8
   31    21    >   NEW                                              $11     'ReflectionClass'
         22        SEND_VAR_EX                                              !2
         23        DO_FCALL                                      0          
         24        ASSIGN                                                   !3, $11
   33    25        INIT_METHOD_CALL                                         !3, 'newInstanceArgs'
         26        SEND_VAR_EX                                              !1
         27        DO_FCALL                                      0  $14     
         28      > RETURN                                                   $14
   34    29*     > RETURN                                                   null

End of function buildentity

End of class Project\Model\Entity\EntityFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.16 ms | 1396 KiB | 17 Q