3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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) { return new static(5001, $data); } public static function bar($data = null) { return new static(6001, $data); } } $e = E::foo(); $s = $e->setData('snowflake'); foreach (E::getAll() as $error) { echo $error . PHP_EOL; } var_dump($e, $s);
based on D7XpO
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
Jump found. Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
Jump found. Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 19
Jump found. Position 1 = -2
Branch analysis from position: 19
filename:       /in/MI7RL
function name:  (null)
number of ops:  25
compiled vars:  !0 = $e, !1 = $s, !2 = $error
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  26     0  E >   NOP                                                      
         1        NOP                                                      
 153     2        NOP                                                      
         3        NOP                                                      
 171     4        INIT_STATIC_METHOD_CALL                                  'WordPress%5CError%5CE', 'foo'
         5        DO_FCALL                                      0  $7      
         6        ASSIGN                                                   !0, $7
 172     7        INIT_METHOD_CALL                                         !0, 'setData'
         8        SEND_VAL_EX                                              'snowflake'
         9        DO_FCALL                                      0  $9      
        10        ASSIGN                                                   !1, $9
 174    11        INIT_STATIC_METHOD_CALL                                  'WordPress%5CError%5CE', 'getAll'
        12        DO_FCALL                                      0  $11     
        13      > FE_RESET_R                                       $12     $11, ->19
        14    > > FE_FETCH_R                                               $12, !2, ->19
 175    15    >   FETCH_CONSTANT                                   ~13     'WordPress%5CError%5CPHP_EOL'
        16        CONCAT                                           ~14     !2, ~13
        17        ECHO                                                     ~14
        18      > JMP                                                      ->14
        19    >   FE_FREE                                                  $12
 178    20        INIT_NS_FCALL_BY_NAME                                    
        21        SEND_VAR_EX                                              !0
        22        SEND_VAR_EX                                              !1
        23        DO_FCALL                                      0          
        24      > RETURN                                                   1

Class WordPress\Error\AbstractError:
Function __construct:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
Jump found. Position 1 = -2
Branch analysis from position: 15
Jump found. Position 1 = -2
filename:       /in/MI7RL
function name:  __construct
number of ops:  31
compiled vars:  !0 = $code, !1 = $data, !2 = $previous, !3 = $this
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_CLASS                                 515  :4      
         4        FETCH_IS                                         $5      'codeMessages', $4
         5        ISSET_ISEMPTY_DIM_OBJ                       33554432  ~6      $5, !0
         6        BOOL_NOT                                         ~7      ~6
         7      > JMPZ                                                     ~7, ->15
  61     8    >   NEW                                              $8      :-3
         9        ROPE_INIT                                     3  ~10     'Invalid+error+code+%5B'
        10        ROPE_ADD                                      1  ~10     ~10, !0
        11        ROPE_END                                      2  ~9      ~10, '%5D'
        12        SEND_VAL_EX                                              ~9
        13        DO_FCALL                                      0          
        14      > THROW                                         0          $8
  63    15    >   FETCH_CLASS                                 514  :13     
        16        INIT_STATIC_METHOD_CALL                                  $13
        17        FETCH_CLASS                                 515  :14     
        18        FETCH_FUNC_ARG               unknown             $15     'codeMessages'
        19        FETCH_DIM_FUNC_ARG                               $16     $15, !0
        20        SEND_VAR_EX                                              $16
        21        SEND_VAR_EX                                              !0
        22        SEND_VAR_EX                                              !2
        23        DO_FCALL                                      0          
  64    24        ASSIGN_OBJ                                               'data'
        25        OP_DATA                                                  !1
  65    26        FETCH_CLASS                                 513  :19     
        27        FETCH_W                      static member       $20     'instances'
        28        ASSIGN_DIM                                               $20
        29        OP_DATA                                                  !3
  66    30      > RETURN                                                   null

End of function __construct

Function remove:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
Jump found. Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
Jump found. Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
Jump found. Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
Branch analysis from position: 14
Jump found. Position 1 = -2
Branch analysis from position: 14
filename:       /in/MI7RL
function name:  remove
number of ops:  16
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_CLASS                                 513  :3      
         2        FETCH_R                      static member       $4      'instances'
         3      > FE_RESET_R                                       $5      $4, ->14
         4    > > FE_FETCH_R                                       ~6      $5, !1, ->14
         5    >   ASSIGN                                                   !2, ~6
  76     6        INIT_METHOD_CALL                                         !1, 'getCode'
         7        DO_FCALL                                      0  $8      
         8        IS_IDENTICAL                                     ~9      !0, $8
         9      > JMPZ                                                     ~9, ->13
  77    10    >   FETCH_CLASS                                 513  :10     
        11        FETCH_UNSET                                      $11     'instances', $10
        12        UNSET_DIM                                                $11, !2
        13    > > JMP                                                      ->4
        14    >   FE_FREE                                                  $5
  80    15      > RETURN                                                   null

End of function remove

Function get:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
Jump found. Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
Jump found. Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
Jump found. Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
Branch analysis from position: 11
Jump found. Position 1 = -2
Branch analysis from position: 11
filename:       /in/MI7RL
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      
  91     1        FETCH_CLASS                                 513  :2      
         2        FETCH_R                      static member       $3      'instances'
         3      > FE_RESET_R                                       $4      $3, ->11
         4    > > FE_FETCH_R                                               $4, !1, ->11
  92     5    >   INIT_METHOD_CALL                                         !1, 'getCode'
         6        DO_FCALL                                      0  $5      
         7        IS_IDENTICAL                                     ~6      !0, $5
         8      > JMPZ                                                     ~6, ->10
  93     9    >   YIELD                                                    !1
        10    > > JMP                                                      ->4
        11    >   FE_FREE                                                  $4
  96    12      > GENERATOR_RETURN                                         

End of function get

Function getall:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
Jump found. Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
Jump found. Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 6
Jump found. Position 1 = -2
Branch analysis from position: 6
filename:       /in/MI7RL
function name:  getAll
number of ops:  8
compiled vars:  !0 = $error
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
 105     0  E >   FETCH_CLASS                                 513  :1      
         1        FETCH_R                      static member       $2      'instances'
         2      > FE_RESET_R                                       $3      $2, ->6
         3    > > FE_FETCH_R                                               $3, !0, ->6
 106     4    >   YIELD                                                    !0
         5      > JMP                                                      ->3
         6    >   FE_FREE                                                  $3
 108     7      > GENERATOR_RETURN                                         

End of function getall

Function getdata:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/MI7RL
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
Jump found. Position 1 = -2
filename:       /in/MI7RL
function name:  setData
number of ops:  11
compiled vars:  !0 = $data, !1 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
 127     0  E >   RECV_INIT                                        !0      null
 129     1        FETCH_CLASS                                 515  :2      
         2        NEW                                              $3      :2
         3        INIT_METHOD_CALL                                         'getCode'
         4        DO_FCALL                                      0  $4      
         5        SEND_VAR_NO_REF                               4          $4
         6        SEND_VAR_EX                                              !0
         7        SEND_VAR_EX                                              !1
         8        DO_FCALL                                      0          
         9      > RETURN                                                   $3
 130    10*     > RETURN                                                   null

End of function setdata

Function trigger:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/MI7RL
function name:  trigger
number of ops:  8
compiled vars:  !0 = $type, !1 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
 137     0  E >   RECV_INIT                                        !0      <const:'WordPress\Error\E_USER_NOTICE'>
 139     1        INIT_NS_FCALL_BY_NAME                                    
         2        CAST                                          6  ~2      !1
         3        SEND_VAL_EX                                              ~2
         4        CAST                                          4  ~3      !0
         5        SEND_VAL_EX                                              ~3
         6        DO_FCALL                                      0          
 140     7      > RETURN                                                   null

End of function trigger

Function __tostring:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/MI7RL
function name:  __toString
number of ops:  9
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      > RETURN                                                   ~4
 150     8*     > 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
Jump found. Position 1 = -2
filename:       /in/MI7RL
function name:  foo
number of ops:  8
compiled vars:  !0 = $data
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
 160     0  E >   RECV_INIT                                        !0      null
 162     1        FETCH_CLASS                                 515  :1      
         2        NEW                                              $2      :1
         3        SEND_VAL_EX                                              5001
         4        SEND_VAR_EX                                              !0
         5        DO_FCALL                                      0          
         6      > RETURN                                                   $2
 163     7*     > RETURN                                                   null

End of function foo

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

End of function bar

Function __construct:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
Jump found. Position 1 = -2
Branch analysis from position: 15
Jump found. Position 1 = -2
filename:       /in/MI7RL
function name:  __construct
number of ops:  31
compiled vars:  !0 = $code, !1 = $data, !2 = $previous, !3 = $this
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_CLASS                                 515  :4      
         4        FETCH_IS                                         $5      'codeMessages', $4
         5        ISSET_ISEMPTY_DIM_OBJ                       33554432  ~6      $5, !0
         6        BOOL_NOT                                         ~7      ~6
         7      > JMPZ                                                     ~7, ->15
  61     8    >   NEW                                              $8      :-3
         9        ROPE_INIT                                     3  ~10     'Invalid+error+code+%5B'
        10        ROPE_ADD                                      1  ~10     ~10, !0
        11        ROPE_END                                      2  ~9      ~10, '%5D'
        12        SEND_VAL_EX                                              ~9
        13        DO_FCALL                                      0          
        14      > THROW                                         0          $8
  63    15    >   FETCH_CLASS                                 514  :13     
        16        INIT_STATIC_METHOD_CALL                                  $13
        17        FETCH_CLASS                                 515  :14     
        18        FETCH_FUNC_ARG               unknown             $15     'codeMessages'
        19        FETCH_DIM_FUNC_ARG                               $16     $15, !0
        20        SEND_VAR_EX                                              $16
        21        SEND_VAR_EX                                              !0
        22        SEND_VAR_EX                                              !2
        23        DO_FCALL                                      0          
  64    24        ASSIGN_OBJ                                               'data'
        25        OP_DATA                                                  !1
  65    26        FETCH_CLASS                                 513  :19     
        27        FETCH_W                      static member       $20     'instances'
        28        ASSIGN_DIM                                               $20
        29        OP_DATA                                                  !3
  66    30      > RETURN                                                   null

End of function __construct

Function remove:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
Jump found. Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
Jump found. Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
Jump found. Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
Branch analysis from position: 14
Jump found. Position 1 = -2
Branch analysis from position: 14
filename:       /in/MI7RL
function name:  remove
number of ops:  16
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_CLASS                                 513  :3      
         2        FETCH_R                      static member       $4      'instances'
         3      > FE_RESET_R                                       $5      $4, ->14
         4    > > FE_FETCH_R                                       ~6      $5, !1, ->14
         5    >   ASSIGN                                                   !2, ~6
  76     6        INIT_METHOD_CALL                                         !1, 'getCode'
         7        DO_FCALL                                      0  $8      
         8        IS_IDENTICAL                                     ~9      !0, $8
         9      > JMPZ                                                     ~9, ->13
  77    10    >   FETCH_CLASS                                 513  :10     
        11        FETCH_UNSET                                      $11     'instances', $10
        12        UNSET_DIM                                                $11, !2
        13    > > JMP                                                      ->4
        14    >   FE_FREE                                                  $5
  80    15      > RETURN                                                   null

End of function remove

Function get:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
Jump found. Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
Jump found. Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
Jump found. Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
Branch analysis from position: 11
Jump found. Position 1 = -2
Branch analysis from position: 11
filename:       /in/MI7RL
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      
  91     1        FETCH_CLASS                                 513  :2      
         2        FETCH_R                      static member       $3      'instances'
         3      > FE_RESET_R                                       $4      $3, ->11
         4    > > FE_FETCH_R                                               $4, !1, ->11
  92     5    >   INIT_METHOD_CALL                                         !1, 'getCode'
         6        DO_FCALL                                      0  $5      
         7        IS_IDENTICAL                                     ~6      !0, $5
         8      > JMPZ                                                     ~6, ->10
  93     9    >   YIELD                                                    !1
        10    > > JMP                                                      ->4
        11    >   FE_FREE                                                  $4
  96    12      > GENERATOR_RETURN                                         

End of function get

Function getall:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
Jump found. Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
Jump found. Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 6
Jump found. Position 1 = -2
Branch analysis from position: 6
filename:       /in/MI7RL
function name:  getAll
number of ops:  8
compiled vars:  !0 = $error
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
 105     0  E >   FETCH_CLASS                                 513  :1      
         1        FETCH_R                      static member       $2      'instances'
         2      > FE_RESET_R                                       $3      $2, ->6
         3    > > FE_FETCH_R                                               $3, !0, ->6
 106     4    >   YIELD                                                    !0
         5      > JMP                                                      ->3
         6    >   FE_FREE                                                  $3
 108     7      > GENERATOR_RETURN                                         

End of function getall

Function getdata:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/MI7RL
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
Jump found. Position 1 = -2
filename:       /in/MI7RL
function name:  setData
number of ops:  11
compiled vars:  !0 = $data, !1 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
 127     0  E >   RECV_INIT                                        !0      null
 129     1        FETCH_CLASS                                 515  :2      
         2        NEW                                              $3      :2
         3        INIT_METHOD_CALL                                         'getCode'
         4        DO_FCALL                                      0  $4      
         5        SEND_VAR_NO_REF                               4          $4
         6        SEND_VAR_EX                                              !0
         7        SEND_VAR_EX                                              !1
         8        DO_FCALL                                      0          
         9      > RETURN                                                   $3
 130    10*     > RETURN                                                   null

End of function setdata

Function trigger:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/MI7RL
function name:  trigger
number of ops:  8
compiled vars:  !0 = $type, !1 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
 137     0  E >   RECV_INIT                                        !0      <const:'WordPress\Error\E_USER_NOTICE'>
 139     1        INIT_NS_FCALL_BY_NAME                                    
         2        CAST                                          6  ~2      !1
         3        SEND_VAL_EX                                              ~2
         4        CAST                                          4  ~3      !0
         5        SEND_VAL_EX                                              ~3
         6        DO_FCALL                                      0          
 140     7      > RETURN                                                   null

End of function trigger

Function __tostring:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/MI7RL
function name:  __toString
number of ops:  9
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      > RETURN                                                   ~4
 150     8*     > RETURN                                                   null

End of function __tostring

End of class WordPress\Error\E.

Generated using Vulcan Logic Dumper, using php 7.3.0