3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace MabeEnum; use ReflectionClass; use InvalidArgumentException; use LogicException; abstract class Enum { /** * The selected value * * @var null|boolean|int|float|string */ private $value; /** * The ordinal number of the value * * @var null|int */ private $ordinal; /** * An array of available constants by class * * @var array ["$class" => ["$const" => $value, ...], ...] */ private static $constants = array(); /** * Already instantiated enums * * @var array ["$class" => ["$const" => $instance, ...], ...] */ private static $instances = array(); /** * Constructor * * @param null|boolean|int|float|string $value The value to select * @param int|null $ordinal The ordinal number of the value */ final private function __construct($value, $ordinal = null) { $this->value = $value; $this->ordinal = $ordinal; } /** * Get the current selected constant name * * @return string * @see getName() */ public function __toString() { return $this->getName(); } /** * @throws LogicException Enums are not cloneable * because instances are implemented as singletons */ final private function __clone() { throw new LogicException('Enums are not cloneable'); } /** * @throws LogicException Enums are not serializable * because instances are implemented as singletons */ final public function __sleep() { throw new LogicException('Enums are not serializable'); } /** * @throws LogicException Enums are not serializable * because instances are implemented as singletons */ final public function __wakeup() { throw new LogicException('Enums are not serializable'); } /** * Get the current selected value * * @return null|boolean|int|float|string */ final public function getValue() { return $this->value; } /** * Get the current selected constant name * * @return string */ final public function getName() { return array_search($this->value, self::detectConstants(get_called_class()), true); } /** * Get the ordinal number of the selected value * * @return int */ final public function getOrdinal() { if ($this->ordinal !== null) { return $this->ordinal; } // detect ordinal $ordinal = 0; $value = $this->value; foreach (self::detectConstants(get_called_class()) as $constValue) { if ($value === $constValue) { break; } ++$ordinal; } $this->ordinal = $ordinal; return $ordinal; } /** * Compare this enum against another enum and check if it's the same value * * @param mixed $value * @return boolean */ final public function is($enum) { return $this->value === $enum || (($enum instanceof static || $this instanceof $enum) && $this->value === $enum->getValue()); } /** * Get an enum of the given value * * @param static|null|boolean|int|float|string $value * @return static * @throws InvalidArgumentException On an unknwon or invalid value * @throws LogicException On ambiguous constant values */ final public static function get($value) { if ($value instanceof static) { $value = $value->getValue(); } $class = get_called_class(); $constants = self::detectConstants($class); $name = array_search($value, $constants, true); if ($name === false) { if (is_scalar($value)) { throw new InvalidArgumentException('Unknown value ' . var_export($value, true)); } else { throw new InvalidArgumentException('Invalid value of type ' . gettype($value)); } } if (isset(self::$instances[$class][$name])) { return self::$instances[$class][$name]; } return self::$instances[$class][$name] = new $class($constants[$name]); } /** * Get an enum by the given name * * @param string $name The name to instantiate the enum by * @return static * @throws InvalidArgumentException On an invalid or unknown name * @throws LogicException On ambiguous constant values */ final public static function getByName($name) { $name = (string) $name; $class = get_called_class(); if (isset(self::$instances[$class][$name])) { return self::$instances[$class][$name]; } $const = $class . '::' . $name; if (!defined($const)) { throw new InvalidArgumentException($const . ' not defined'); } return self::$instances[$class][$name] = new $class(constant($const)); } /** * Get an enum by the given ordinal number * * @param int $ordinal The ordinal number to instantiate the enum by * @return static * @throws InvalidArgumentException On an invalid ordinal number * @throws LogicException On ambiguous constant values */ final public static function getByOrdinal($ordinal) { $ordinal = (int) $ordinal; $class = get_called_class(); $constants = self::detectConstants($class); $item = array_slice($constants, $ordinal, 1, false); if (!$item) { throw new InvalidArgumentException(sprintf( 'Invalid ordinal number, must between 0 and %s', count($constants) - 1 )); } $name = key($item); if (isset(self::$instances[$class][$name])) { return self::$instances[$class][$name]; } return self::$instances[$class][$name] = new $class(current($item), $ordinal); } /** * Clears all instantiated enums * * NOTE: This can break singleton behavior ... use it with caution! * * @return void */ final public static function clear() { $class = get_called_class(); unset(self::$instances[$class], self::$constants[$class]); } /** * Get all available constants of the called class * * @return array * @throws LogicException On ambiguous constant values */ final public static function getConstants() { return self::detectConstants(get_called_class()); } /** * Detect constants available by given class * * @param string $class * @return array * @throws LogicException On ambiguous constant values */ private static function detectConstants($class) { var_dump(get_called_class()); if (!isset(self::$constants[$class])) { $reflection = new ReflectionClass($class); $constants = $reflection->getConstants(); // values needs to be unique $ambiguous = array(); foreach ($constants as $value) { $names = array_keys($constants, $value, true); if (count($names) > 1) { $ambiguous[var_export($value, true)] = $names; } } if ($ambiguous) { throw new LogicException( 'All possible values needs to be unique. The following are ambiguous: ' . implode(', ', array_map(function ($names) use ($constants) { return implode('/', $names) . '=' . var_export($constants[$names[0]], true); }, $ambiguous)) ); } // This is required to make sure that constants of base classes will be the first while (($reflection = $reflection->getParentClass()) && $reflection->name !== __CLASS__) { $constants = $reflection->getConstants() + $constants; } self::$constants[$class] = $constants; } return self::$constants[$class]; } /** * Instantiate an enum by a name of a constant. * * This will be called automatically on calling a method * with the same name of a defined constant. * * @param string $method The name to instantiate the enum by (called as method) * @param array $args There should be no arguments * @return static * @throws InvalidArgumentException On an invalid or unknown name * @throws LogicException On ambiguous constant values */ final public static function __callStatic($method, array $args) { return self::getByName($method); } } class TestEnum1 extends Enum { const TEST1 = 'TEST1'; } class TestEnum2 extends TestEnum1 { const TEST2 = 'TEST2'; } $test1 = TestEnum1::get('TEST1'); $test2 = TestEnum2::get('TEST2');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vakvQ
function name:  (null)
number of ops:  12
compiled vars:  !0 = $test1, !1 = $test2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'mabeenum%5Cenum'
  316     1        DECLARE_CLASS                                            'mabeenum%5Ctestenum1', 'mabeenum%5Cenum'
  321     2        DECLARE_CLASS                                            'mabeenum%5Ctestenum2', 'mabeenum%5Ctestenum1'
  325     3        INIT_STATIC_METHOD_CALL                                  'MabeEnum%5CTestEnum1', 'get'
          4        SEND_VAL_EX                                              'TEST1'
          5        DO_FCALL                                      0  $2      
          6        ASSIGN                                                   !0, $2
  326     7        INIT_STATIC_METHOD_CALL                                  'MabeEnum%5CTestEnum2', 'get'
          8        SEND_VAL_EX                                              'TEST2'
          9        DO_FCALL                                      0  $4      
         10        ASSIGN                                                   !1, $4
         11      > RETURN                                                   1

Function %00mabeenum%5C%7Bclosure%7D%2Fin%2FvakvQ%3A281%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vakvQ
function name:  MabeEnum\{closure}
number of ops:  17
compiled vars:  !0 = $names, !1 = $constants
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  281     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
  282     2        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cimplode'
          3        SEND_VAL_EX                                              '%2F'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $2      
          6        CONCAT                                           ~3      $2, '%3D'
          7        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_export'
          8        CHECK_FUNC_ARG                                           
          9        FETCH_DIM_R                                      ~4      !0, 0
         10        FETCH_DIM_FUNC_ARG                               $5      !1, ~4
         11        SEND_FUNC_ARG                                            $5
         12        SEND_VAL_EX                                              <true>
         13        DO_FCALL                                      0  $6      
         14        CONCAT                                           ~7      ~3, $6
         15      > RETURN                                                   ~7
  283    16*     > RETURN                                                   null

End of function %00mabeenum%5C%7Bclosure%7D%2Fin%2FvakvQ%3A281%240

Class MabeEnum\Enum:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vakvQ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $value, !1 = $ordinal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   48     2        ASSIGN_OBJ                                               'value'
          3        OP_DATA                                                  !0
   49     4        ASSIGN_OBJ                                               'ordinal'
          5        OP_DATA                                                  !1
   50     6      > RETURN                                                   null

End of function __construct

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

End of function __tostring

Function __clone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/vakvQ
function name:  __clone
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   NEW                                              $0      'LogicException'
          1        SEND_VAL_EX                                              'Enums+are+not+cloneable'
          2        DO_FCALL                                      0          
          3      > THROW                                         0          $0
   70     4*     > RETURN                                                   null

End of function __clone

Function __sleep:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/vakvQ
function name:  __sleep
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   NEW                                              $0      'LogicException'
          1        SEND_VAL_EX                                              'Enums+are+not+serializable'
          2        DO_FCALL                                      0          
          3      > THROW                                         0          $0
   79     4*     > RETURN                                                   null

End of function __sleep

Function __wakeup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/vakvQ
function name:  __wakeup
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   NEW                                              $0      'LogicException'
          1        SEND_VAL_EX                                              'Enums+are+not+serializable'
          2        DO_FCALL                                      0          
          3      > THROW                                         0          $0
   88     4*     > RETURN                                                   null

End of function __wakeup

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

End of function getvalue

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vakvQ
function name:  getName
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  107     0  E >   INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Carray_search'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $0      'value'
          3        SEND_FUNC_ARG                                            $0
          4        INIT_STATIC_METHOD_CALL                                  'detectConstants'
          5        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cget_called_class'
          6        DO_FCALL                                      0  $1      
          7        SEND_VAR_NO_REF_EX                                       $1
          8        DO_FCALL                                      0  $2      
          9        SEND_VAR_NO_REF_EX                                       $2
         10        SEND_VAL_EX                                              <true>
         11        DO_FCALL                                      0  $3      
         12      > RETURN                                                   $3
  108    13*     > RETURN                                                   null

End of function getname

Function getordinal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 20
Branch analysis from position: 20
filename:       /in/vakvQ
function name:  getOrdinal
number of ops:  25
compiled vars:  !0 = $ordinal, !1 = $value, !2 = $constValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  117     0  E >   FETCH_OBJ_R                                      ~3      'ordinal'
          1        TYPE_CHECK                                  1020          ~3
          2      > JMPZ                                                     ~4, ->5
  118     3    >   FETCH_OBJ_R                                      ~5      'ordinal'
          4      > RETURN                                                   ~5
  122     5    >   ASSIGN                                                   !0, 0
  123     6        FETCH_OBJ_R                                      ~7      'value'
          7        ASSIGN                                                   !1, ~7
  124     8        INIT_STATIC_METHOD_CALL                                  'detectConstants'
          9        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cget_called_class'
         10        DO_FCALL                                      0  $9      
         11        SEND_VAR_NO_REF_EX                                       $9
         12        DO_FCALL                                      0  $10     
         13      > FE_RESET_R                                       $11     $10, ->20
         14    > > FE_FETCH_R                                               $11, !2, ->20
  125    15    >   IS_IDENTICAL                                             !1, !2
         16      > JMPZ                                                     ~12, ->18
  126    17    > > JMP                                                      ->20
  128    18    >   PRE_INC                                                  !0
  124    19      > JMP                                                      ->14
         20    >   FE_FREE                                                  $11
  131    21        ASSIGN_OBJ                                               'ordinal'
         22        OP_DATA                                                  !0
  132    23      > RETURN                                                   !0
  133    24*     > RETURN                                                   null

End of function getordinal

Function is:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 10
Branch analysis from position: 17
filename:       /in/vakvQ
function name:  is
number of ops:  19
compiled vars:  !0 = $enum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  141     0  E >   RECV                                             !0      
  143     1        FETCH_OBJ_R                                      ~1      'value'
          2        IS_IDENTICAL                                     ~2      !0, ~1
          3      > JMPNZ_EX                                         ~2      ~2, ->17
  144     4    >   INSTANCEOF                                       ~3      !0
          5      > JMPNZ_EX                                         ~3      ~3, ->10
          6    >   FETCH_THIS                                       ~4      
          7        FETCH_CLASS                                   0  $5      !0
          8        INSTANCEOF                                       ~6      ~4, $5
          9        BOOL                                             ~3      ~6
         10    > > JMPZ_EX                                          ~3      ~3, ->16
         11    >   FETCH_OBJ_R                                      ~7      'value'
         12        INIT_METHOD_CALL                                         !0, 'getValue'
         13        DO_FCALL                                      0  $8      
         14        IS_IDENTICAL                                     ~9      $8, ~7
         15        BOOL                                             ~3      ~9
         16    >   BOOL                                             ~2      ~3
         17    > > RETURN                                                   ~2
  145    18*     > RETURN                                                   null

End of function is

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 43
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 35
Branch analysis from position: 25
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 51
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/vakvQ
function name:  get
number of ops:  63
compiled vars:  !0 = $value, !1 = $class, !2 = $constants, !3 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  155     0  E >   RECV                                             !0      
  157     1        INSTANCEOF                                               !0
          2      > JMPZ                                                     ~4, ->6
  158     3    >   INIT_METHOD_CALL                                         !0, 'getValue'
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !0, $5
  161     6    >   INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cget_called_class'
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !1, $7
  162     9        INIT_STATIC_METHOD_CALL                                  'detectConstants'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0  $9      
         12        ASSIGN                                                   !2, $9
  163    13        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Carray_search'
         14        SEND_VAR_EX                                              !0
         15        SEND_VAR_EX                                              !2
         16        SEND_VAL_EX                                              <true>
         17        DO_FCALL                                      0  $11     
         18        ASSIGN                                                   !3, $11
  164    19        TYPE_CHECK                                    4          !3
         20      > JMPZ                                                     ~13, ->43
  165    21    >   INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cis_scalar'
         22        SEND_VAR_EX                                              !0
         23        DO_FCALL                                      0  $14     
         24      > JMPZ                                                     $14, ->35
  166    25    >   NEW                                              $15     'InvalidArgumentException'
         26        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_export'
         27        SEND_VAR_EX                                              !0
         28        SEND_VAL_EX                                              <true>
         29        DO_FCALL                                      0  $16     
         30        CONCAT                                           ~17     'Unknown+value+', $16
         31        SEND_VAL_EX                                              ~17
         32        DO_FCALL                                      0          
         33      > THROW                                         0          $15
         34*       JMP                                                      ->43
  168    35    >   NEW                                              $19     'InvalidArgumentException'
         36        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cgettype'
         37        SEND_VAR_EX                                              !0
         38        DO_FCALL                                      0  $20     
         39        CONCAT                                           ~21     'Invalid+value+of+type+', $20
         40        SEND_VAL_EX                                              ~21
         41        DO_FCALL                                      0          
         42      > THROW                                         0          $19
  172    43    >   FETCH_STATIC_PROP_IS                             ~23     'instances'
         44        FETCH_DIM_IS                                     ~24     ~23, !1
         45        ISSET_ISEMPTY_DIM_OBJ                         0          ~24, !3
         46      > JMPZ                                                     ~25, ->51
  173    47    >   FETCH_STATIC_PROP_R          unknown             ~26     'instances'
         48        FETCH_DIM_R                                      ~27     ~26, !1
         49        FETCH_DIM_R                                      ~28     ~27, !3
         50      > RETURN                                                   ~28
  176    51    >   FETCH_CLASS                                   0  $32     !1
         52        NEW                                              $33     $32
         53        CHECK_FUNC_ARG                                           
         54        FETCH_DIM_FUNC_ARG                               $34     !2, !3
         55        SEND_FUNC_ARG                                            $34
         56        DO_FCALL                                      0          
         57        FETCH_STATIC_PROP_W          unknown             $29     'instances'
         58        FETCH_DIM_W                                      $30     $29, !1
         59        ASSIGN_DIM                                       ~31     $30, !3
         60        OP_DATA                                                  $33
         61      > RETURN                                                   ~31
  177    62*     > RETURN                                                   null

End of function get

Function getbyname:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vakvQ
function name:  getByName
number of ops:  40
compiled vars:  !0 = $name, !1 = $class, !2 = $const
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  187     0  E >   RECV                                             !0      
  189     1        CAST                                          6  ~3      !0
          2        ASSIGN                                                   !0, ~3
  190     3        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cget_called_class'
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !1, $5
  191     6        FETCH_STATIC_PROP_IS                             ~7      'instances'
          7        FETCH_DIM_IS                                     ~8      ~7, !1
          8        ISSET_ISEMPTY_DIM_OBJ                         0          ~8, !0
          9      > JMPZ                                                     ~9, ->14
  192    10    >   FETCH_STATIC_PROP_R          unknown             ~10     'instances'
         11        FETCH_DIM_R                                      ~11     ~10, !1
         12        FETCH_DIM_R                                      ~12     ~11, !0
         13      > RETURN                                                   ~12
  195    14    >   CONCAT                                           ~13     !1, '%3A%3A'
         15        CONCAT                                           ~14     ~13, !0
         16        ASSIGN                                                   !2, ~14
  196    17        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cdefined'
         18        SEND_VAR_EX                                              !2
         19        DO_FCALL                                      0  $16     
         20        BOOL_NOT                                         ~17     $16
         21      > JMPZ                                                     ~17, ->27
  197    22    >   NEW                                              $18     'InvalidArgumentException'
         23        CONCAT                                           ~19     !2, '+not+defined'
         24        SEND_VAL_EX                                              ~19
         25        DO_FCALL                                      0          
         26      > THROW                                         0          $18
  200    27    >   FETCH_CLASS                                   0  $24     !1
         28        NEW                                              $25     $24
         29        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cconstant'
         30        SEND_VAR_EX                                              !2
         31        DO_FCALL                                      0  $26     
         32        SEND_VAR_NO_REF_EX                                       $26
         33        DO_FCALL                                      0          
         34        FETCH_STATIC_PROP_W          unknown             $21     'instances'
         35        FETCH_DIM_W                                      $22     $21, !1
         36        ASSIGN_DIM                                       ~23     $22, !0
         37        OP_DATA                                                  $25
         38      > RETURN                                                   ~23
  201    39*     > RETURN                                                   null

End of function getbyname

Function getbyordinal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 31
Branch analysis from position: 19
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vakvQ
function name:  getByOrdinal
number of ops:  57
compiled vars:  !0 = $ordinal, !1 = $class, !2 = $constants, !3 = $item, !4 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  211     0  E >   RECV                                             !0      
  213     1        CAST                                          4  ~5      !0
          2        ASSIGN                                                   !0, ~5
  214     3        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cget_called_class'
          4        DO_FCALL                                      0  $7      
          5        ASSIGN                                                   !1, $7
  215     6        INIT_STATIC_METHOD_CALL                                  'detectConstants'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $9      
          9        ASSIGN                                                   !2, $9
  216    10        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Carray_slice'
         11        SEND_VAR_EX                                              !2
         12        SEND_VAR_EX                                              !0
         13        SEND_VAL_EX                                              1
         14        SEND_VAL_EX                                              <false>
         15        DO_FCALL                                      0  $11     
         16        ASSIGN                                                   !3, $11
  217    17        BOOL_NOT                                         ~13     !3
         18      > JMPZ                                                     ~13, ->31
  218    19    >   NEW                                              $14     'InvalidArgumentException'
         20        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Csprintf'
  219    21        SEND_VAL_EX                                              'Invalid+ordinal+number%2C+must+between+0+and+%25s'
  220    22        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Ccount'
         23        SEND_VAR_EX                                              !2
         24        DO_FCALL                                      0  $15     
         25        SUB                                              ~16     $15, 1
         26        SEND_VAL_EX                                              ~16
         27        DO_FCALL                                      0  $17     
         28        SEND_VAR_NO_REF_EX                                       $17
         29        DO_FCALL                                      0          
         30      > THROW                                         0          $14
  224    31    >   INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Ckey'
         32        SEND_VAR_EX                                              !3
         33        DO_FCALL                                      0  $19     
         34        ASSIGN                                                   !4, $19
  225    35        FETCH_STATIC_PROP_IS                             ~21     'instances'
         36        FETCH_DIM_IS                                     ~22     ~21, !1
         37        ISSET_ISEMPTY_DIM_OBJ                         0          ~22, !4
         38      > JMPZ                                                     ~23, ->43
  226    39    >   FETCH_STATIC_PROP_R          unknown             ~24     'instances'
         40        FETCH_DIM_R                                      ~25     ~24, !1
         41        FETCH_DIM_R                                      ~26     ~25, !4
         42      > RETURN                                                   ~26
  229    43    >   FETCH_CLASS                                   0  $30     !1
         44        NEW                                              $31     $30
         45        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Ccurrent'
         46        SEND_VAR_EX                                              !3
         47        DO_FCALL                                      0  $32     
         48        SEND_VAR_NO_REF_EX                                       $32
         49        SEND_VAR_EX                                              !0
         50        DO_FCALL                                      0          
         51        FETCH_STATIC_PROP_W          unknown             $27     'instances'
         52        FETCH_DIM_W                                      $28     $27, !1
         53        ASSIGN_DIM                                       ~29     $28, !4
         54        OP_DATA                                                  $31
         55      > RETURN                                                   ~29
  230    56*     > RETURN                                                   null

End of function getbyordinal

Function clear:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vakvQ
function name:  clear
number of ops:  8
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  241     0  E >   INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cget_called_class'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
  242     3        FETCH_STATIC_PROP_UNSET                          $3      'instances'
          4        UNSET_DIM                                                $3, !0
          5        FETCH_STATIC_PROP_UNSET                          $4      'constants'
          6        UNSET_DIM                                                $4, !0
  243     7      > RETURN                                                  

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
264.8 ms | 1420 KiB | 40 Q