3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace MabeEnum; use ReflectionClass; use InvalidArgumentException; use LogicException; /** * Class to implement enumerations for PHP 5 (without SplEnum) * * @link http://github.com/marc-mabe/php-enum for the canonical source repository * @copyright Copyright (c) 2015 Marc Bennewitz * @license http://github.com/marc-mabe/php-enum/blob/master/LICENSE.txt New BSD License */ abstract class Enum { /** * The selected value * * @var null|bool|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|bool|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|bool|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 * * @param mixed $enum * @return bool */ final public function is($enum) { return $this === $enum || $this->value === $enum; /* return $this->value === $enum || (($enum instanceof static || $this instanceof $enum) && $this->value === $enum->getValue()); */ } /** * Get an enum of the given value or instance * * On passing an extended instance the instance will be returned if the value * is inherited by the called class or if $tradeExtendedAsUnknown is disabled * else an InvalidArgumentException will be thrown. * * @param static|null|bool|int|float|string $value * @param bool $tradeExtendedAsUnknown * @return static * @throws InvalidArgumentException On an unknwon or invalid value * @throws LogicException On ambiguous constant values */ final public static function get($value, $tradeExtendedAsUnknown = true) { if ($value instanceof static) { if ($tradeExtendedAsUnknown && !defined('static::' . $value->getName())) { throw new InvalidArgumentException(sprintf( "%s::%s is not inherited from %s", get_class($value), $value->getName(), get_called_class() )); } return $value; } $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, true); 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) { 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 A extends Enum { const UNDEFINED = 0; const ONE = 1; } class B extends A { const ONE = 'ONE'; } // Two enumerators of the same constant on inherited classes $enumAUndef = A::UNDEFINED(); $enumBUndef = B::UNDEFINED(); var_dump($enumAUndef === $enumBUndef); // FALSE - different instances var_dump($enumAUndef->getValue() === $enumBUndef->getValue()); // TRUE - the values will be the same var_dump($enumAUndef->getName() === $enumBUndef->getName()); // TRUE - the constant names will be the same var_dump($enumAUndef->is($enumBUndef)); // FALSE - different instances var_dump($enumBUndef->is($enumAUndef)); // FALSE - different instances var_dump($enumAUndef->is($enumBUndef->getValue())); // TRUE - the values will be the same var_dump($enumBUndef->is($enumAUndef->getValue())); // TRUE - the values will be the same // Two enumerators of the same named constant with different values on inherited classes $enumAOne = A::ONE(); $enumBOne = B::ONE(); var_dump($enumAOne === $enumBOne); // FALSE - different instances var_dump($enumAOne->getValue() === $enumBOne->getValue()); // FALSE - the values will be different var_dump($enumAOne->getName() === $enumBOne->getName()); // TRUE - the constant names will be the same var_dump($enumAOne->getName(), $enumBOne->getName()); var_dump($enumAOne->is($enumBOne)); // FALSE - different instances var_dump($enumBOne->is($enumAOne)); // FALSE - different instances var_dump($enumAOne->is($enumBOne->getValue())); // FALSE - the values will be different var_dump($enumBOne->is($enumAOne->getValue())); // FALSE - the values will be different
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SpJlZ
function name:  (null)
number of ops:  120
compiled vars:  !0 = $enumAUndef, !1 = $enumBUndef, !2 = $enumAOne, !3 = $enumBOne
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   DECLARE_CLASS                                            'mabeenum%5Cenum'
  339     1        DECLARE_CLASS                                            'mabeenum%5Ca', 'mabeenum%5Cenum'
  344     2        DECLARE_CLASS                                            'mabeenum%5Cb', 'mabeenum%5Ca'
  349     3        INIT_STATIC_METHOD_CALL                                  'MabeEnum%5CA', 'UNDEFINED'
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !0, $4
  350     6        INIT_STATIC_METHOD_CALL                                  'MabeEnum%5CB', 'UNDEFINED'
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !1, $6
  352     9        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         10        IS_IDENTICAL                                     ~8      !0, !1
         11        SEND_VAL_EX                                              ~8
         12        DO_FCALL                                      0          
  353    13        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         14        INIT_METHOD_CALL                                         !0, 'getValue'
         15        DO_FCALL                                      0  $10     
         16        INIT_METHOD_CALL                                         !1, 'getValue'
         17        DO_FCALL                                      0  $11     
         18        IS_IDENTICAL                                     ~12     $10, $11
         19        SEND_VAL_EX                                              ~12
         20        DO_FCALL                                      0          
  354    21        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         22        INIT_METHOD_CALL                                         !0, 'getName'
         23        DO_FCALL                                      0  $14     
         24        INIT_METHOD_CALL                                         !1, 'getName'
         25        DO_FCALL                                      0  $15     
         26        IS_IDENTICAL                                     ~16     $14, $15
         27        SEND_VAL_EX                                              ~16
         28        DO_FCALL                                      0          
  355    29        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         30        INIT_METHOD_CALL                                         !0, 'is'
         31        SEND_VAR_EX                                              !1
         32        DO_FCALL                                      0  $18     
         33        SEND_VAR_NO_REF_EX                                       $18
         34        DO_FCALL                                      0          
  356    35        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         36        INIT_METHOD_CALL                                         !1, 'is'
         37        SEND_VAR_EX                                              !0
         38        DO_FCALL                                      0  $20     
         39        SEND_VAR_NO_REF_EX                                       $20
         40        DO_FCALL                                      0          
  357    41        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         42        INIT_METHOD_CALL                                         !0, 'is'
         43        INIT_METHOD_CALL                                         !1, 'getValue'
         44        DO_FCALL                                      0  $22     
         45        SEND_VAR_NO_REF_EX                                       $22
         46        DO_FCALL                                      0  $23     
         47        SEND_VAR_NO_REF_EX                                       $23
         48        DO_FCALL                                      0          
  358    49        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         50        INIT_METHOD_CALL                                         !1, 'is'
         51        INIT_METHOD_CALL                                         !0, 'getValue'
         52        DO_FCALL                                      0  $25     
         53        SEND_VAR_NO_REF_EX                                       $25
         54        DO_FCALL                                      0  $26     
         55        SEND_VAR_NO_REF_EX                                       $26
         56        DO_FCALL                                      0          
  361    57        INIT_STATIC_METHOD_CALL                                  'MabeEnum%5CA', 'ONE'
         58        DO_FCALL                                      0  $28     
         59        ASSIGN                                                   !2, $28
  362    60        INIT_STATIC_METHOD_CALL                                  'MabeEnum%5CB', 'ONE'
         61        DO_FCALL                                      0  $30     
         62        ASSIGN                                                   !3, $30
  364    63        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         64        IS_IDENTICAL                                     ~32     !2, !3
         65        SEND_VAL_EX                                              ~32
         66        DO_FCALL                                      0          
  365    67        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         68        INIT_METHOD_CALL                                         !2, 'getValue'
         69        DO_FCALL                                      0  $34     
         70        INIT_METHOD_CALL                                         !3, 'getValue'
         71        DO_FCALL                                      0  $35     
         72        IS_IDENTICAL                                     ~36     $34, $35
         73        SEND_VAL_EX                                              ~36
         74        DO_FCALL                                      0          
  366    75        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         76        INIT_METHOD_CALL                                         !2, 'getName'
         77        DO_FCALL                                      0  $38     
         78        INIT_METHOD_CALL                                         !3, 'getName'
         79        DO_FCALL                                      0  $39     
         80        IS_IDENTICAL                                     ~40     $38, $39
         81        SEND_VAL_EX                                              ~40
         82        DO_FCALL                                      0          
  367    83        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         84        INIT_METHOD_CALL                                         !2, 'getName'
         85        DO_FCALL                                      0  $42     
         86        SEND_VAR_NO_REF_EX                                       $42
         87        INIT_METHOD_CALL                                         !3, 'getName'
         88        DO_FCALL                                      0  $43     
         89        SEND_VAR_NO_REF_EX                                       $43
         90        DO_FCALL                                      0          
  368    91        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         92        INIT_METHOD_CALL                                         !2, 'is'
         93        SEND_VAR_EX                                              !3
         94        DO_FCALL                                      0  $45     
         95        SEND_VAR_NO_REF_EX                                       $45
         96        DO_FCALL                                      0          
  369    97        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
         98        INIT_METHOD_CALL                                         !3, 'is'
         99        SEND_VAR_EX                                              !2
        100        DO_FCALL                                      0  $47     
        101        SEND_VAR_NO_REF_EX                                       $47
        102        DO_FCALL                                      0          
  370   103        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
        104        INIT_METHOD_CALL                                         !2, 'is'
        105        INIT_METHOD_CALL                                         !3, 'getValue'
        106        DO_FCALL                                      0  $49     
        107        SEND_VAR_NO_REF_EX                                       $49
        108        DO_FCALL                                      0  $50     
        109        SEND_VAR_NO_REF_EX                                       $50
        110        DO_FCALL                                      0          
  371   111        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_dump'
        112        INIT_METHOD_CALL                                         !3, 'is'
        113        INIT_METHOD_CALL                                         !2, 'getValue'
        114        DO_FCALL                                      0  $52     
        115        SEND_VAR_NO_REF_EX                                       $52
        116        DO_FCALL                                      0  $53     
        117        SEND_VAR_NO_REF_EX                                       $53
        118        DO_FCALL                                      0          
        119      > RETURN                                                   1

Function %00mabeenum%5C%7Bclosure%7D%2Fin%2FSpJlZ%3A302%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SpJlZ
function name:  MabeEnum\{closure}
number of ops:  17
compiled vars:  !0 = $names, !1 = $constants
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  302     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
  303     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
  304    16*     > RETURN                                                   null

End of function %00mabeenum%5C%7Bclosure%7D%2Fin%2FSpJlZ%3A302%240

Class MabeEnum\Enum:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SpJlZ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $value, !1 = $ordinal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   54     2        ASSIGN_OBJ                                               'value'
          3        OP_DATA                                                  !0
   55     4        ASSIGN_OBJ                                               'ordinal'
          5        OP_DATA                                                  !1
   56     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/SpJlZ
function name:  __toString
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   INIT_METHOD_CALL                                         'getName'
          1        DO_FCALL                                      0  $0      
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   67     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/SpJlZ
function name:  __clone
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   NEW                                              $0      'LogicException'
          1        SEND_VAL_EX                                              'Enums+are+not+cloneable'
          2        DO_FCALL                                      0          
          3      > THROW                                         0          $0
   76     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/SpJlZ
function name:  __sleep
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   NEW                                              $0      'LogicException'
          1        SEND_VAL_EX                                              'Enums+are+not+serializable'
          2        DO_FCALL                                      0          
          3      > THROW                                         0          $0
   85     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/SpJlZ
function name:  __wakeup
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E >   NEW                                              $0      'LogicException'
          1        SEND_VAL_EX                                              'Enums+are+not+serializable'
          2        DO_FCALL                                      0          
          3      > THROW                                         0          $0
   94     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/SpJlZ
function name:  getValue
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  103     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1      > RETURN                                                   ~0
  104     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/SpJlZ
function name:  getName
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  113     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
  114    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/SpJlZ
function name:  getOrdinal
number of ops:  25
compiled vars:  !0 = $ordinal, !1 = $value, !2 = $constValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  123     0  E >   FETCH_OBJ_R                                      ~3      'ordinal'
          1        TYPE_CHECK                                  1020          ~3
          2      > JMPZ                                                     ~4, ->5
  124     3    >   FETCH_OBJ_R                                      ~5      'ordinal'
          4      > RETURN                                                   ~5
  128     5    >   ASSIGN                                                   !0, 0
  129     6        FETCH_OBJ_R                                      ~7      'value'
          7        ASSIGN                                                   !1, ~7
  130     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
  131    15    >   IS_IDENTICAL                                             !1, !2
         16      > JMPZ                                                     ~12, ->18
  132    17    > > JMP                                                      ->20
  134    18    >   PRE_INC                                                  !0
  130    19      > JMP                                                      ->14
         20    >   FE_FREE                                                  $11
  137    21        ASSIGN_OBJ                                               'ordinal'
         22        OP_DATA                                                  !0
  138    23      > RETURN                                                   !0
  139    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 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/SpJlZ
function name:  is
number of ops:  9
compiled vars:  !0 = $enum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  147     0  E >   RECV                                             !0      
  149     1        FETCH_THIS                                       ~1      
          2        IS_IDENTICAL                                     ~2      !0, ~1
          3      > JMPNZ_EX                                         ~2      ~2, ->7
          4    >   FETCH_OBJ_R                                      ~3      'value'
          5        IS_IDENTICAL                                     ~4      !0, ~3
          6        BOOL                                             ~2      ~4
          7    > > RETURN                                                   ~2
  154     8*     > RETURN                                                   null

End of function is

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 32
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 31
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 69
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 61
Branch analysis from position: 51
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 61
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 77
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SpJlZ
function name:  get
number of ops:  89
compiled vars:  !0 = $value, !1 = $tradeExtendedAsUnknown, !2 = $class, !3 = $constants, !4 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  169     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
  171     2        INSTANCEOF                                               !0
          3      > JMPZ                                                     ~5, ->32
  172     4    > > JMPZ_EX                                          ~6      !1, ->13
          5    >   INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cdefined'
          6        INIT_METHOD_CALL                                         !0, 'getName'
          7        DO_FCALL                                      0  $7      
          8        CONCAT                                           ~8      'static%3A%3A', $7
          9        SEND_VAL_EX                                              ~8
         10        DO_FCALL                                      0  $9      
         11        BOOL_NOT                                         ~10     $9
         12        BOOL                                             ~6      ~10
         13    > > JMPZ                                                     ~6, ->31
  173    14    >   NEW                                              $11     'InvalidArgumentException'
         15        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Csprintf'
  174    16        SEND_VAL_EX                                              '%25s%3A%3A%25s+is+not+inherited+from+%25s'
  175    17        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cget_class'
         18        SEND_VAR_EX                                              !0
         19        DO_FCALL                                      0  $12     
         20        SEND_VAR_NO_REF_EX                                       $12
  176    21        INIT_METHOD_CALL                                         !0, 'getName'
         22        DO_FCALL                                      0  $13     
         23        SEND_VAR_NO_REF_EX                                       $13
  177    24        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cget_called_class'
         25        DO_FCALL                                      0  $14     
         26        SEND_VAR_NO_REF_EX                                       $14
         27        DO_FCALL                                      0  $15     
         28        SEND_VAR_NO_REF_EX                                       $15
         29        DO_FCALL                                      0          
         30      > THROW                                         0          $11
  180    31    > > RETURN                                                   !0
  183    32    >   INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cget_called_class'
         33        DO_FCALL                                      0  $17     
         34        ASSIGN                                                   !2, $17
  184    35        INIT_STATIC_METHOD_CALL                                  'detectConstants'
         36        SEND_VAR_EX                                              !2
         37        DO_FCALL                                      0  $19     
         38        ASSIGN                                                   !3, $19
  185    39        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Carray_search'
         40        SEND_VAR_EX                                              !0
         41        SEND_VAR_EX                                              !3
         42        SEND_VAL_EX                                              <true>
         43        DO_FCALL                                      0  $21     
         44        ASSIGN                                                   !4, $21
  186    45        TYPE_CHECK                                    4          !4
         46      > JMPZ                                                     ~23, ->69
  187    47    >   INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cis_scalar'
         48        SEND_VAR_EX                                              !0
         49        DO_FCALL                                      0  $24     
         50      > JMPZ                                                     $24, ->61
  188    51    >   NEW                                              $25     'InvalidArgumentException'
         52        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cvar_export'
         53        SEND_VAR_EX                                              !0
         54        SEND_VAL_EX                                              <true>
         55        DO_FCALL                                      0  $26     
         56        CONCAT                                           ~27     'Unknown+value+', $26
         57        SEND_VAL_EX                                              ~27
         58        DO_FCALL                                      0          
         59      > THROW                                         0          $25
         60*       JMP                                                      ->69
  190    61    >   NEW                                              $29     'InvalidArgumentException'
         62        INIT_NS_FCALL_BY_NAME                                    'MabeEnum%5Cgettype'
         63        SEND_VAR_EX                                              !0
         64        DO_FCALL                                      0  $30     
         65        CONCAT                                           ~31     'Invalid+value+of+type+', $30
         66        SEND_VAL_EX                                              ~31
         67        DO_FCALL                                      0          
         68      > THROW                                         0          $29
  194    69    >   FETCH_STATIC_PROP_IS                             ~33     'instances'
         70        FETCH_DIM_IS                                     ~34     ~33, !2
         71        ISSET_ISEMPTY_DIM_OBJ                         0          ~34, !4
         72      > JMPZ                                                     ~35, ->77
  195    73    >   FETCH_STATIC_PROP_R          unknown             ~36     'instances'
         74        FETCH_DIM_R                                      ~37     ~36, !2
         75        FETCH_DIM_R                                      ~38     ~37, !4
         76      > RETURN                                                   ~38
  198    77    >   FETCH_CLASS                                   0  $42     !2
         78        NEW                                              $43     $42
         79        CHECK_FUNC_ARG                                           
         80        FETCH_DIM_FUNC_ARG                               $44     !3, !4
         81        SEND_FUNC_ARG                                            $44
         82        DO_FCALL                                      0          
         83        FETCH_STATIC_PROP_W          unknown             $39     'instances'
         84        FETCH_DIM_W                                      $40     $39, !2
         85        ASSIGN_DIM                                       ~41     $40, !4
         86        OP_DATA                                                  $43
         87      > RETURN                                                   ~41
  199    88*     > 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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.98 ms | 1428 KiB | 33 Q