3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @method static LocationType GROUP_OF_STATES() * @method static LocationType STATE() * @method static LocationType REGION() * @method static LocationType CITY() * @method static LocationType DISTRICT() * @method static LocationType ADDRESS() */ class LocationType extends EnumBASE { const GROUP_OF_STATES = "GROUP-OF-STATES"; const STATE = "STATE"; const REGION = "REGION"; const CITY = "CITY"; const DISTRICT = "DISTRICT"; const ADDRESS = "ADDRESS"; } var_dump(LocationType::GROUP_OF_STATES()); var_dump(LocationType::REGION()); var_dump(LocationType::ADDRESS()); abstract class EnumBASE { static function getAll() { $x = new ReflectionClass(static::class); foreach($x->getConstants() as $constantValue) yield new static($constantValue); } private $name; private $value; /** * Constructs by value * * @param int|float|string|bool|null $enumValue */ final function __construct($enumValue) { $valid = false; foreach((new ReflectionClass($this))->getConstants() as $constantName => $constantValue) { if($constantValue === $enumValue) { $this->name = $constantName; $this->value = $constantValue; $valid = true; break; } } if(!$valid) throw new ExceptionDomain("Enum is invalid."); } /** * Constructs by name * * @param string $method * @param mixed[] $params * @return static */ final static function __callStatic($method, $params) { return new static(constant(get_called_class() . "::" . $method)); } /** * TODO * * @return string */ function getName() { return $this->name; } /** * TODO * * @return mixed */ function getValue() { return $this->value; } function __toString() { return $this->getName(); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG0ml
function name:  (null)
number of ops:  18
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   DECLARE_CLASS                                            'locationtype', 'enumbase'
   21     1        INIT_FCALL                                               'var_dump'
          2        INIT_STATIC_METHOD_CALL                                  'LocationType', 'GROUP_OF_STATES'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   22     6        INIT_FCALL                                               'var_dump'
          7        INIT_STATIC_METHOD_CALL                                  'LocationType', 'REGION'
          8        DO_FCALL                                      0  $2      
          9        SEND_VAR                                                 $2
         10        DO_ICALL                                                 
   23    11        INIT_FCALL                                               'var_dump'
         12        INIT_STATIC_METHOD_CALL                                  'LocationType', 'ADDRESS'
         13        DO_FCALL                                      0  $4      
         14        SEND_VAR                                                 $4
         15        DO_ICALL                                                 
   28    16        DECLARE_CLASS                                            'enumbase'
   98    17      > RETURN                                                   1

Class LocationType: [no user functions]
Class EnumBASE:
Function getall:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 15
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 15
filename:       /in/YG0ml
function name:  getAll
number of ops:  17
compiled vars:  !0 = $x, !1 = $constantValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   GENERATOR_CREATE                                         
   32     1        NEW                                              $2      'ReflectionClass'
          2        FETCH_CLASS_NAME                                 ~3      
          3        SEND_VAL_EX                                              ~3
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
   33     6        INIT_METHOD_CALL                                         !0, 'getConstants'
          7        DO_FCALL                                      0  $6      
          8      > FE_RESET_R                                       $7      $6, ->15
          9    > > FE_FETCH_R                                               $7, !1, ->15
   34    10    >   NEW                          static              $8      
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0          
         13        YIELD                                                    $8
   33    14      > JMP                                                      ->9
         15    >   FE_FREE                                                  $7
   35    16      > GENERATOR_RETURN                                         

End of function getall

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 20
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 20
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 20
Branch analysis from position: 20
filename:       /in/YG0ml
function name:  __construct
number of ops:  28
compiled vars:  !0 = $enumValue, !1 = $valid, !2 = $constantValue, !3 = $constantName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1        ASSIGN                                                   !1, <false>
   48     2        NEW                                              $5      'ReflectionClass'
          3        FETCH_THIS                                       $6      
          4        SEND_VAR_EX                                              $6
          5        DO_FCALL                                      0          
          6        INIT_METHOD_CALL                                         $5, 'getConstants'
          7        DO_FCALL                                      0  $8      
          8      > FE_RESET_R                                       $9      $8, ->20
          9    > > FE_FETCH_R                                       ~10     $9, !2, ->20
         10    >   ASSIGN                                                   !3, ~10
   50    11        IS_IDENTICAL                                             !2, !0
         12      > JMPZ                                                     ~12, ->19
   52    13    >   ASSIGN_OBJ                                               'name'
         14        OP_DATA                                                  !3
   53    15        ASSIGN_OBJ                                               'value'
         16        OP_DATA                                                  !2
   54    17        ASSIGN                                                   !1, <true>
   55    18      > JMP                                                      ->20
   48    19    > > JMP                                                      ->9
         20    >   FE_FREE                                                  $9
   58    21        BOOL_NOT                                         ~16     !1
         22      > JMPZ                                                     ~16, ->27
   59    23    >   NEW                                              $17     'ExceptionDomain'
         24        SEND_VAL_EX                                              'Enum+is+invalid.'
         25        DO_FCALL                                      0          
         26      > THROW                                         0          $17
   60    27    > > RETURN                                                   null

End of function __construct

Function __callstatic:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG0ml
function name:  __callStatic
number of ops:  13
compiled vars:  !0 = $method, !1 = $params
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   71     2        NEW                          static              $2      
          3        INIT_FCALL                                               'constant'
          4        GET_CALLED_CLASS                                 ~3      
          5        CONCAT                                           ~4      ~3, '%3A%3A'
          6        CONCAT                                           ~5      ~4, !0
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                         $6      
          9        SEND_VAR_NO_REF_EX                                       $6
         10        DO_FCALL                                      0          
         11      > RETURN                                                   $2
   72    12*     > RETURN                                                   null

End of function __callstatic

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG0ml
function name:  getName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1      > RETURN                                                   ~0
   82     2*     > RETURN                                                   null

End of function getname

Function getvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG0ml
function name:  getValue
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1      > RETURN                                                   ~0
   92     2*     > RETURN                                                   null

End of function getvalue

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG0ml
function name:  __toString
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   96     0  E >   INIT_METHOD_CALL                                         'getName'
          1        DO_FCALL                                      0  $0      
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   97     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function __tostring

End of class EnumBASE.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.94 ms | 1404 KiB | 17 Q