mpyw / exceper

Provides temporary error handler automatically using set_error_handler() and restore_error_handler().

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convert::to(string, callable, int) does not handle $severity

chitoku-k opened this issue · comments

Convert::to does not properly set ErrorException::$severity when called via to(string, callable, int) signature:

<?php
// OK: \ErrorException::$severity is set
// Using Convert::toErrorException, which handles it manually
Convert::toErrorException(function () {
    var_dump($undefined);
});

// NG: \ErrorException::$severity is default
// Using Convert::to, which does not specifically treat \ErrorException
Convert::to(\ErrorException::class, function () {
    var_dump($undefined);
});

This behavior is slightly confusing as they are neither documented nor logical.

This does not handle \ErrorException when $class is equal to \ErrorException, which begins with \, whilst it can be instantiated.

exceper/src/Convert.php

Lines 89 to 93 in a887c36

if (strcasecmp($class, 'ErrorException')) {
throw Core::rewriteLocation(new $class($message), $file, $line);
} else {
throw new \ErrorException($message, 0, $severity, $file, $line);
}