3v4l.org

run code in 300+ PHP versions simultaneously
<?php //use ErrorException; //use InvalidArgumentException; /** * HTTP Status values have a code (int) and reason (string). * * @internal Implemented similar to a type-safe enum. * * @property-read int $code the status code * @property-read string $reason the status description */ final class Status { /** @var array (int) code => (string) reason */ private static $codeReasons = [ 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-status', 208 => 'Already Reported', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Switch Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Unordered Collection', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', 508 => 'Loop Detected', 511 => 'Network Authentication Required', ]; /** @var self[] */ private static $instances = []; /** @var int */ private $code; /** @var string */ private $reason; /** * Singleton constructor * * @param int $aCode an http status code * @throws InvalidArgumentException on invalid code */ private function __construct($aCode) { if (!static::validate($aCode)) { throw new InvalidArgumentExeption("Invalid status code: [$aCode]"); } $this->code = (int) $aCode; $this->reason = static::$codeReasons[$this->code]; } /** * Factory constructor * * Methods must not start with a number, so an underscore prefix is necessary. * * @example $status = Status::_404(); * * @param string $aMethod a status code prefixed with an underscore * @param array $arguments unused arguments passed to the magic method * @return self */ public static function __callStatic($aMethod, array $arguments = []) { $aMethod = trim($aMethod, '_'); if (!isset(static::$instances[$aMethod])) { static::$instances[$aMethod] = new static($aMethod); } return static::$instances[$aMethod]; } /** * List all HTTP statuses * * @yield self */ public static function listAll() { foreach (static::$codeReasons as $code => $reason) { yield $code => $reason; } } /** * Verify that a code is valid * * @param int $aCode the status code to verify * @return bool */ public static function validate($aCode) { return ($aCode instanceof self) || isset(static::$codeReasons[(int) $aCode]); } /** * Allow public property access * * @param string $aProperty * @return mixed * @throws ErrorException on invalid property */ public function __get($aProperty) { if (property_exists($this, $aProperty)) { return $this->{$aProperty}; } $debug = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $error = sprintf('Undefined property %s::$%s', __CLASS__, $aProperty); throw new ErrorException($error, 0, E_USER_NOTICE, $debug[1]['file'], $debug[1]['line']); } /** @return string */ public function __toString() { return $this->code . ' ' . $this->reason; } } var_dump(iterator_to_array(Status::listAll()));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VnM59
function name:  (null)
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   DECLARE_CLASS                                            'status'
  168     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'iterator_to_array'
          3        INIT_STATIC_METHOD_CALL                                  'Status', 'listAll'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                         $1      
          7        SEND_VAR                                                 $1
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Class Status:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VnM59
function name:  __construct
number of ops:  22
compiled vars:  !0 = $aCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   RECV                                             !0      
   94     1        INIT_STATIC_METHOD_CALL                                  'validate'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        BOOL_NOT                                         ~2      $1
          5      > JMPZ                                                     ~2, ->13
   95     6    >   NEW                                              $3      'InvalidArgumentExeption'
          7        ROPE_INIT                                     3  ~5      'Invalid+status+code%3A+%5B'
          8        ROPE_ADD                                      1  ~5      ~5, !0
          9        ROPE_END                                      2  ~4      ~5, '%5D'
         10        SEND_VAL_EX                                              ~4
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $3
   97    13    >   CAST                                          4  ~9      !0
         14        ASSIGN_OBJ                                               'code'
         15        OP_DATA                                                  ~9
   98    16        FETCH_OBJ_R                                      ~12     'code'
         17        FETCH_STATIC_PROP_R          unknown             ~11     'codeReasons'
         18        FETCH_DIM_R                                      ~13     ~11, ~12
         19        ASSIGN_OBJ                                               'reason'
         20        OP_DATA                                                  ~13
   99    21      > RETURN                                                   null

End of function __construct

Function __callstatic:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/VnM59
function name:  __callStatic
number of ops:  21
compiled vars:  !0 = $aMethod, !1 = $arguments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  112     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
  114     2        INIT_FCALL                                               'trim'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '_'
          5        DO_ICALL                                         $2      
          6        ASSIGN                                                   !0, $2
  115     7        FETCH_STATIC_PROP_IS                             ~4      'instances'
          8        ISSET_ISEMPTY_DIM_OBJ                         0  ~5      ~4, !0
          9        BOOL_NOT                                         ~6      ~5
         10      > JMPZ                                                     ~6, ->17
  116    11    >   NEW                          static              $9      
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
         14        FETCH_STATIC_PROP_W          unknown             $7      'instances'
         15        ASSIGN_DIM                                               $7, !0
         16        OP_DATA                                                  $9
  118    17    >   FETCH_STATIC_PROP_R          unknown             ~11     'instances'
         18        FETCH_DIM_R                                      ~12     ~11, !0
         19      > RETURN                                                   ~12
  119    20*     > RETURN                                                   null

End of function __callstatic

Function listall:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 7
filename:       /in/VnM59
function name:  listAll
number of ops:  9
compiled vars:  !0 = $reason, !1 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  126     0  E >   GENERATOR_CREATE                                         
  128     1        FETCH_STATIC_PROP_R          unknown             ~2      'codeReasons'
          2      > FE_RESET_R                                       $3      ~2, ->7
          3    > > FE_FETCH_R                                       ~4      $3, !0, ->7
          4    >   ASSIGN                                                   !1, ~4
  129     5        YIELD                                                    !0, !1
  128     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $3
  131     8      > GENERATOR_RETURN                                         

End of function listall

Function validate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/VnM59
function name:  validate
number of ops:  9
compiled vars:  !0 = $aCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  139     0  E >   RECV                                             !0      
  141     1        INSTANCEOF                                       ~1      !0
          2      > JMPNZ_EX                                         ~1      ~1, ->7
          3    >   CAST                                          4  ~3      !0
          4        FETCH_STATIC_PROP_IS                             ~2      'codeReasons'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~4      ~2, ~3
          6        BOOL                                             ~1      ~4
          7    > > RETURN                                                   ~1
  142     8*     > RETURN                                                   null

End of function validate

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/VnM59
function name:  __get
number of ops:  35
compiled vars:  !0 = $aProperty, !1 = $debug, !2 = $error
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  151     0  E >   RECV                                             !0      
  153     1        INIT_FCALL                                               'property_exists'
          2        FETCH_THIS                                       ~3      
          3        SEND_VAL                                                 ~3
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $4      
          6      > JMPZ                                                     $4, ->9
  154     7    >   FETCH_OBJ_R                                      ~5      !0
          8      > RETURN                                                   ~5
  156     9    >   INIT_FCALL                                               'debug_backtrace'
         10        SEND_VAL                                                 2
         11        SEND_VAL                                                 2
         12        DO_ICALL                                         $6      
         13        ASSIGN                                                   !1, $6
  157    14        INIT_FCALL                                               'sprintf'
         15        SEND_VAL                                                 'Undefined+property+%25s%3A%3A%24%25s'
         16        SEND_VAL                                                 'Status'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $8      
         19        ASSIGN                                                   !2, $8
  158    20        NEW                                              $10     'ErrorException'
         21        SEND_VAR_EX                                              !2
         22        SEND_VAL_EX                                              0
         23        SEND_VAL_EX                                              1024
         24        CHECK_FUNC_ARG                                           
         25        FETCH_DIM_FUNC_ARG                               $11     !1, 1
         26        FETCH_DIM_FUNC_ARG                               $12     $11, 'file'
         27        SEND_FUNC_ARG                                            $12
         28        CHECK_FUNC_ARG                                           
         29        FETCH_DIM_FUNC_ARG                               $13     !1, 1
         30        FETCH_DIM_FUNC_ARG                               $14     $13, 'line'
         31        SEND_FUNC_ARG                                            $14
         32        DO_FCALL                                      0          
         33      > THROW                                         0          $10
  159    34*     > RETURN                                                   null

End of function __get

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VnM59
function name:  __toString
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  164     0  E >   FETCH_OBJ_R                                      ~0      'code'
          1        CONCAT                                           ~1      ~0, '+'
          2        FETCH_OBJ_R                                      ~2      'reason'
          3        CONCAT                                           ~3      ~1, ~2
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
  165     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function __tostring

End of class Status.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.32 ms | 1408 KiB | 25 Q