3 namespace Drupal\Component\Assertion;
6 * Handler for runtime assertion failures.
8 * This class allows PHP 5.x to throw exceptions on runtime assertion fails
9 * in the same manner as PHP 7, and sets the ASSERT_EXCEPTION flag to TRUE
10 * for the PHP 7 runtime.
17 * Registers uniform assertion handling.
19 public static function register() {
20 // Since we're using exceptions, turn error warnings off.
21 assert_options(ASSERT_WARNING, FALSE);
23 if (version_compare(PHP_VERSION, '7.0.0-dev') < 0) {
24 if (!class_exists('AssertionError', FALSE)) {
25 require __DIR__ . '/global_namespace_php5.php';
27 // PHP 5 - create a handler to throw the exception directly.
28 assert_options(ASSERT_CALLBACK, function($file = '', $line = 0, $code = '', $message = '') {
29 if (empty($message)) {
32 throw new \AssertionError($message, 0, NULL, $file, $line);
36 // PHP 7 - just turn exception throwing on.
37 assert_options(ASSERT_EXCEPTION, TRUE);