The PHP ErrorException::getSeverity API performs a focused operation on an object or value. The examples below show its effect on actual data.
Returns the PHP error severity constant recorded in an ErrorException.
What Is ErrorException::getSeverity in PHP?
Returns the PHP error severity constant recorded in an ErrorException.
Syntax:
ErrorException::getSeverity(): int
This operation has no parameters.
Return type declared by PHP: int. The value or side effect is demonstrated in the examples below.
Example 1: Basic Usage
This example uses a small input to make the main behavior visible.
<?php
$issue = new ErrorException("Invalid configuration", 0, E_USER_WARNING);
echo $issue->getSeverity();
Output:
512
Returns the PHP error severity constant recorded in an ErrorException.
Example 2: A Different Input
A different set of values shows the same operation in another situation.
<?php
$issue = new ErrorException("Missing record", 0, E_USER_NOTICE);
echo $issue->getSeverity();
Output:
1024
The severity is an integer bitmask constant, not an HTTP status code.
Practical Example: Applying the Feature
This example shows an application-style use of the feature, with its surrounding setup visible.
<?php
$issue = new ErrorException("Validation failed", 0, E_USER_ERROR);
echo $issue->getSeverity();
Output:
256
The code is shown for learning. Adjust the class names, inputs and error handling to suit your application.
Important Behavior and Edge Cases
- The severity is an integer bitmask constant, not an HTTP status code.
- Returns the PHP error severity constant recorded in an ErrorException.
- Observe differences in empty inputs, invalid states and optional extension availability where relevant.
Comparison With Related Approaches
| Approach | Important Difference |
|---|---|
ErrorException::getSeverity | Returns the PHP error severity constant recorded in an ErrorException. |
| Exception | ErrorException additionally records an error-severity level, which a plain Exception does not provide. |
Common Beginner Mistakes
| Mistake | Correct Approach |
|---|---|
Ignoring the documented state or precondition of ErrorException::getSeverity | The severity is an integer bitmask constant, not an HTTP status code. |
| Expecting a different type of result | Read the declared return type and distinguish returned values from changes to the source object. |
| Assuming a related API works identically | ErrorException additionally records an error-severity level, which a plain Exception does not provide. |
Key Takeaways
- Returns the PHP error severity constant recorded in an ErrorException.
- The severity is an integer bitmask constant, not an HTTP status code.
- Use the example that matches the values, runtime version and dependencies in your application.
ErrorException::getSeverity is useful when its behavior matches the data structure and lifecycle of your PHP application. Choose it with a clear understanding of its preconditions and returned values.