3v4l.org

run code in 300+ PHP versions simultaneously
<?php enum Language: int { case English = 1; case Spanish = 2; public static function fromName(string $name): Language { return (new \ReflectionEnum(static::class))->getCase($name)->getValue(); } } $english = Language::from(1); $spanish = Language::from(2); $english = Language::fromName('English'); $spanish = Language::fromName('Spanish'); var_dump([ 'name' => $english->name, 'value' => $english->value, ]); // this will result in an error: Language::fromName('Arabic');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HAcuL
function name:  (null)
number of ops:  28
compiled vars:  !0 = $english, !1 = $spanish
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_CLASS                                            'language'
   14     1        INIT_STATIC_METHOD_CALL                                  'Language', 'from'
          2        SEND_VAL_EX                                              1
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   15     5        INIT_STATIC_METHOD_CALL                                  'Language', 'from'
          6        SEND_VAL_EX                                              2
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !1, $4
   17     9        INIT_STATIC_METHOD_CALL                                  'Language', 'fromName'
         10        SEND_VAL_EX                                              'English'
         11        DO_FCALL                                      0  $6      
         12        ASSIGN                                                   !0, $6
   18    13        INIT_STATIC_METHOD_CALL                                  'Language', 'fromName'
         14        SEND_VAL_EX                                              'Spanish'
         15        DO_FCALL                                      0  $8      
         16        ASSIGN                                                   !1, $8
   20    17        INIT_FCALL                                               'var_dump'
   21    18        FETCH_OBJ_R                                      ~10     !0, 'name'
         19        INIT_ARRAY                                       ~11     ~10, 'name'
   22    20        FETCH_OBJ_R                                      ~12     !0, 'value'
         21        ADD_ARRAY_ELEMENT                                ~11     ~12, 'value'
         22        SEND_VAL                                                 ~11
   20    23        DO_ICALL                                                 
   28    24        INIT_STATIC_METHOD_CALL                                  'Language', 'fromName'
         25        SEND_VAL_EX                                              'Arabic'
         26        DO_FCALL                                      0          
         27      > RETURN                                                   1

Class Language:
Function fromname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HAcuL
function name:  fromName
number of ops:  14
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        NEW                                              $1      'ReflectionEnum'
          2        FETCH_CLASS_NAME                                 ~2      
          3        SEND_VAL_EX                                              ~2
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $1, 'getCase'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $4      
          8        INIT_METHOD_CALL                                         $4, 'getValue'
          9        DO_FCALL                                      0  $5      
         10        VERIFY_RETURN_TYPE                                       $5
         11      > RETURN                                                   $5
   11    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function fromname

End of class Language.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.99 ms | 1015 KiB | 14 Q