3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * AbstractError.php * * @package WordPress\Error */ namespace WordPress\Error; use InvalidArgumentException; use RuntimeException; /** * WordPress Errors extend {@link RuntimeException} with relevant data. * * Extend this class with domain-specific codes and messages and call this * constructor to include the instance in the list of recorded errors. * * Use {@link is_wp_error()} to check if this class is returned. Many core * WordPress functions pass this class in the event of an error and if not * handled properly will result in code errors. * * @package WordPress\Error * @since 2.1.0 */ abstract class AbstractError extends RuntimeException { /** * Internal map of code messages * * @var array code (int) => message (string) */ protected static $codeMessages = []; /** * Internal list of AbstractError instances * * @var self[] */ private static $instances = []; /** * Optional error data * * @var mixed */ private $data; /** * Initialize the error * * @param int $code an error code * @param mixed $data optional error data * @param self $previous optional previous error * * @throws InvalidArgumentException when the code is not recognized */ public function __construct($code, $data = null, self $previous = null) { if (!isset(static::$codeMessages[$code])) { throw new InvalidArgumentException("Invalid error code [$code]"); } parent::__construct(static::$codeMessages[$code], $code, $previous); $this->data = $data; self::$instances[] = $this; } /** * Remove all instances having the specified code * * @param int $code an error code to remove */ final public static function remove($code) { foreach (self::$instances as $index => $error) { if ($code === $error->getCode()) { unset(self::$instances[$index]); } } } /** * Retrieve all instances having the specified code * * @param int $code an error code * * @yield self each error instance with matching code */ final public static function get($code) { foreach (self::$instances as $error) { if ($code === $error->getCode()) { yield $error; } } } /** * Retrieve all error instances * * @yield self each error instance */ final public static function getAll() { foreach (self::$instances as $error) { yield $error; } } /** * Retrieve the error data * * @return mixed error data, if available */ public function getData() { return $this->data; } /** * Replace the error data * * @param mixed $data optional error data * * @return self an instance with the new data */ public function setData($data = null) { return new static($this->getCode(), $data, $this); } /** * Triggers a PHP error * * @param int $type optional PHP error type */ public function trigger($type = E_USER_NOTICE) { trigger_error((string) $this, (int) $type); } /** * Converts the object to a string * * @return string a formatted error string */ public function __toString() { return "Error " . $this->getCode() . ": " . $this->getMessage(); } } class E extends AbstractError { protected static $codeMessages = [ 5001 => 'foo', 6001 => 'bar' ]; public static function foo($data = null, self $previous = null) { return new static(5001, $data, $previous); } public static function bar($data = null, self $previous = null) { return new static(6001, $data, $previous); } } $e = E::foo(); foreach (AbstractError::getAll() as $error) { echo $error->getMessage() . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/n0v3W
function name:  (null)
number of ops:  17
compiled vars:  !0 = $e, !1 = $error
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   DECLARE_CLASS                                            'wordpress%5Cerror%5Cabstracterror', 'runtimeexception'
  153     1        DECLARE_CLASS                                            'wordpress%5Cerror%5Ce', 'wordpress%5Cerror%5Cabstracterror'
  171     2        INIT_STATIC_METHOD_CALL                                  'WordPress%5CError%5CE', 'foo'
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
  173     5        INIT_STATIC_METHOD_CALL                                  'WordPress%5CError%5CAbstractError', 'getAll'
          6        DO_FCALL                                      0  $4      
          7      > FE_RESET_R                                       $5      $4, ->15
          8    > > FE_FETCH_R                                               $5, !1, ->15
  174     9    >   INIT_METHOD_CALL                                         !1, 'getMessage'
         10        DO_FCALL                                      0  $6      
         11        FETCH_CONSTANT                                   ~7      'WordPress%5CError%5CPHP_EOL'
         12        CONCAT                                           ~8      $6, ~7
         13        ECHO                                                     ~8
  173    14      > JMP                                                      ->8
         15    >   FE_FREE                                                  $5
  175    16      > RETURN                                                   1

Class WordPress\Error\AbstractError:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n0v3W
function name:  __construct
number of ops:  29
compiled vars:  !0 = $code, !1 = $data, !2 = $previous
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
   60     3        FETCH_STATIC_PROP_IS                             ~3      'codeMessages'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~4      ~3, !0
          5        BOOL_NOT                                         ~5      ~4
          6      > JMPZ                                                     ~5, ->14
   61     7    >   NEW                                              $6      'InvalidArgumentException'
          8        ROPE_INIT                                     3  ~8      'Invalid+error+code+%5B'
          9        ROPE_ADD                                      1  ~8      ~8, !0
         10        ROPE_END                                      2  ~7      ~8, '%5D'
         11        SEND_VAL_EX                                              ~7
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $6
   63    14    >   INIT_STATIC_METHOD_CALL                                  
         15        CHECK_FUNC_ARG                                           
         16        FETCH_STATIC_PROP_FUNC_ARG   unknown             $11     'codeMessages'
         17        FETCH_DIM_FUNC_ARG                               $12     $11, !0
         18        SEND_FUNC_ARG                                            $12
         19        SEND_VAR_EX                                              !0
         20        SEND_VAR_EX                                              !2
         21        DO_FCALL                                      0          
   64    22        ASSIGN_OBJ                                               'data'
         23        OP_DATA                                                  !1
   65    24        FETCH_THIS                                       ~17     
         25        FETCH_STATIC_PROP_W          unknown             $15     'instances'
         26        ASSIGN_DIM                                               $15
         27        OP_DATA                                                  ~17
   66    28      > RETURN                                                   null

End of function __construct

Function remove:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/n0v3W
function name:  remove
number of ops:  14
compiled vars:  !0 = $code, !1 = $error, !2 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
   75     1        FETCH_STATIC_PROP_R          unknown             ~3      'instances'
          2      > FE_RESET_R                                       $4      ~3, ->12
          3    > > FE_FETCH_R                                       ~5      $4, !1, ->12
          4    >   ASSIGN                                                   !2, ~5
   76     5        INIT_METHOD_CALL                                         !1, 'getCode'
          6        DO_FCALL                                      0  $7      
          7        IS_IDENTICAL                                             !0, $7
          8      > JMPZ                                                     ~8, ->11
   77     9    >   FETCH_STATIC_PROP_UNSET                          $9      'instances'
         10        UNSET_DIM                                                $9, !2
   75    11    > > JMP                                                      ->3
         12    >   FE_FREE                                                  $4
   80    13      > RETURN                                                   null

End of function remove

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
Branch analysis from position: 11
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 11
filename:       /in/n0v3W
function name:  get
number of ops:  13
compiled vars:  !0 = $code, !1 = $error
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   91     2        FETCH_STATIC_PROP_R          unknown             ~2      'instances'
          3      > FE_RESET_R                                       $3      ~2, ->11
          4    > > FE_FETCH_R                                               $3, !1, ->11
   92     5    >   INIT_METHOD_CALL                                         !1, 'getCode'
          6        DO_FCALL                                      0  $4      
          7        IS_IDENTICAL                                             !0, $4
          8      > JMPZ                                                     ~5, ->10
   93     9    >   YIELD                                                    !1
   91    10    > > JMP                                                      ->4
         11    >   FE_FREE                                                  $3
   96    12      > GENERATOR_RETURN                                         

End of function get

Function getall:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 6
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 6
filename:       /in/n0v3W
function name:  getAll
number of ops:  8
compiled vars:  !0 = $error
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  103     0  E >   GENERATOR_CREATE                                         
  105     1        FETCH_STATIC_PROP_R          unknown             ~1      'instances'
          2      > FE_RESET_R                                       $2      ~1, ->6
          3    > > FE_FETCH_R                                               $2, !0, ->6
  106     4    >   YIELD                                                    !0
  105     5      > JMP                                                      ->3
          6    >   FE_FREE                                                  $2
  108     7      > GENERATOR_RETURN                                         

End of function getall

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

End of function getdata

Function setdata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n0v3W
function name:  setData
number of ops:  11
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  127     0  E >   RECV_INIT                                        !0      null
  129     1        NEW                          static              $1      
          2        INIT_METHOD_CALL                                         'getCode'
          3        DO_FCALL                                      0  $2      
          4        SEND_VAR_NO_REF_EX                                       $2
          5        SEND_VAR_EX                                              !0
          6        FETCH_THIS                                       $3      
          7        SEND_VAR_EX                                              $3
          8        DO_FCALL                                      0          
          9      > RETURN                                                   $1
  130    10*     > RETURN                                                   null

End of function setdata

Function trigger:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n0v3W
function name:  trigger
number of ops:  9
compiled vars:  !0 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  137     0  E >   RECV_INIT                                        !0      <const ast>
  139     1        INIT_NS_FCALL_BY_NAME                                    'WordPress%5CError%5Ctrigger_error'
          2        FETCH_THIS                                       ~1      
          3        CAST                                          6  ~2      ~1
          4        SEND_VAL_EX                                              ~2
          5        CAST                                          4  ~3      !0
          6        SEND_VAL_EX                                              ~3
          7        DO_FCALL                                      0          
  140     8      > RETURN                                                   null

End of function trigger

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n0v3W
function name:  __toString
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  149     0  E >   INIT_METHOD_CALL                                         'getCode'
          1        DO_FCALL                                      0  $0      
          2        CONCAT                                           ~1      'Error+', $0
          3        CONCAT                                           ~2      ~1, '%3A+'
          4        INIT_METHOD_CALL                                         'getMessage'
          5        DO_FCALL                                      0  $3      
          6        CONCAT                                           ~4      ~2, $3
          7        VERIFY_RETURN_TYPE                                       ~4
          8      > RETURN                                                   ~4
  150     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function __tostring

End of class WordPress\Error\AbstractError.

Class WordPress\Error\E:
Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n0v3W
function name:  foo
number of ops:  9
compiled vars:  !0 = $data, !1 = $previous
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  160     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
  162     2        NEW                          static              $2      
          3        SEND_VAL_EX                                              5001
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
          7      > RETURN                                                   $2
  163     8*     > RETURN                                                   null

End of function foo

Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n0v3W
function name:  bar
number of ops:  9
compiled vars:  !0 = $data, !1 = $previous
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  165     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
  167     2        NEW                          static              $2      
          3        SEND_VAL_EX                                              6001
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
          7      > RETURN                                                   $2
  168     8*     > RETURN                                                   null

End of function bar

End of class WordPress\Error\E.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.16 ms | 1412 KiB | 15 Q