3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Gender { const UNKNOWN = 0; const MALE = 1; const FEMALE = 2; const NOT_APPLICABLE = 9; public static function from($value) { static $names; if ( ! $names) { $class = new ReflectionClass(self::class); $constants = $class->getConstants(); $names = array_keys($constants); } foreach ($names as $name) { if (constant(__CLASS__ . '::' . $name) === $value) { return $name; } } throw new InvalidArgumentException('No matching gender for value ' . $value); } // no instances allowed private function __construct() {} } echo Gender::from(Gender::FEMALE); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dp8PE
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_STATIC_METHOD_CALL                                  'Gender', 'from'
          1        SEND_VAL                                                 2
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   35     4      > RETURN                                                   1

Class Gender:
Function from:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 26
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 15
filename:       /in/Dp8PE
function name:  from
number of ops:  33
compiled vars:  !0 = $value, !1 = $names, !2 = $class, !3 = $constants, !4 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        BIND_STATIC                                              !1
   13     2        BOOL_NOT                                         ~5      !1
          3      > JMPZ                                                     ~5, ->15
   14     4    >   NEW                                              $6      'ReflectionClass'
          5        SEND_VAL_EX                                              'Gender'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !2, $6
   15     8        INIT_METHOD_CALL                                         !2, 'getConstants'
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !3, $9
   16    11        INIT_FCALL                                               'array_keys'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !1, $11
   19    15    > > FE_RESET_R                                       $13     !1, ->26
         16    > > FE_FETCH_R                                               $13, !4, ->26
   20    17    >   INIT_FCALL                                               'constant'
         18        CONCAT                                           ~14     'Gender%3A%3A', !4
         19        SEND_VAL                                                 ~14
         20        DO_ICALL                                         $15     
         21        IS_IDENTICAL                                             !0, $15
         22      > JMPZ                                                     ~16, ->25
   21    23    >   FE_FREE                                                  $13
         24      > RETURN                                                   !4
   19    25    > > JMP                                                      ->16
         26    >   FE_FREE                                                  $13
   25    27        NEW                                              $17     'InvalidArgumentException'
         28        CONCAT                                           ~18     'No+matching+gender+for+value+', !0
         29        SEND_VAL_EX                                              ~18
         30        DO_FCALL                                      0          
         31      > THROW                                         0          $17
   26    32*     > RETURN                                                   null

End of function from

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dp8PE
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E > > RETURN                                                   null

End of function __construct

End of class Gender.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.46 ms | 1400 KiB | 17 Q