Skip to content

Commit

Permalink
ext/mysqli: Remove catchable fatal error handler
Browse files Browse the repository at this point in the history
Recoverable fatal error haven't been a thing for a while, and proper fatal error have never been catchable
  • Loading branch information
Girgias committed Jul 29, 2023
1 parent 8582d97 commit b389846
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 51 deletions.
16 changes: 0 additions & 16 deletions ext/mysqli/tests/connect.inc
Expand Up @@ -99,19 +99,3 @@
}
return false;
}

function handle_catchable_fatal($errno, $error, $file, $line) {
static $errcodes = array();
if (empty($errcodes)) {
$constants = get_defined_constants();
foreach ($constants as $name => $value) {
if (substr($name, 0, 2) == "E_")
$errcodes[$value] = $name;
}
}
printf("[%s] %s in %s on line %s\n",
(isset($errcodes[$errno])) ? $errcodes[$errno] : $errno,
$error, $file, $line);

return true;
}
24 changes: 11 additions & 13 deletions ext/mysqli/tests/mysqli_fetch_object.phpt
Expand Up @@ -10,8 +10,6 @@ require_once('skipifconnectfailure.inc');
<?php
include_once("connect.inc");

set_error_handler('handle_catchable_fatal');

require('table.inc');
if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 5")) {
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
Expand Down Expand Up @@ -58,7 +56,7 @@ require_once('skipifconnectfailure.inc');
var_dump($obj);
}
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
Expand All @@ -68,7 +66,7 @@ require_once('skipifconnectfailure.inc');
var_dump($obj);
}
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

$obj = mysqli_fetch_object($res, 'mysqli_fetch_object_construct', array('a', 'b'));
Expand Down Expand Up @@ -104,8 +102,8 @@ require_once('skipifconnectfailure.inc');
try {
if (false !== ($obj = @mysqli_fetch_object($res, 'mysqli_fetch_object_construct', 'a')))
printf("[011] Should have failed\n");
} catch (Error $e) {
handle_catchable_fatal($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

mysqli_free_result($res);
Expand All @@ -131,8 +129,8 @@ require_once('skipifconnectfailure.inc');

try {
var_dump(mysqli_fetch_object($res, 'this_class_does_not_exist'));
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}


Expand All @@ -143,12 +141,12 @@ require_once('skipifconnectfailure.inc');
<?php
require_once("clean_table.inc");
?>
--EXPECTF--
Exception: Too few arguments to function mysqli_fetch_object_construct::__construct(), 0 passed and exactly 2 expected
Exception: Too few arguments to function mysqli_fetch_object_construct::__construct(), 1 passed and exactly 2 expected
--EXPECT--
ArgumentCountError: Too few arguments to function mysqli_fetch_object_construct::__construct(), 0 passed and exactly 2 expected
ArgumentCountError: Too few arguments to function mysqli_fetch_object_construct::__construct(), 1 passed and exactly 2 expected
NULL
NULL
mysqli_result object is already closed
[0] mysqli_fetch_object(): Argument #3 ($constructor_args) must be of type array, string given in %s on line %d
mysqli_fetch_object(): Argument #2 ($class) must be a valid class name, this_class_does_not_exist given
TypeError: mysqli_fetch_object(): Argument #3 ($constructor_args) must be of type array, string given
TypeError: mysqli_fetch_object(): Argument #2 ($class) must be a valid class name, this_class_does_not_exist given
done!
43 changes: 21 additions & 22 deletions ext/mysqli/tests/mysqli_fetch_object_oo.phpt
Expand Up @@ -9,13 +9,12 @@ require_once('skipifconnectfailure.inc');
--FILE--
<?php
require_once("connect.inc");
set_error_handler('handle_catchable_fatal');

$mysqli = new mysqli();
try {
new mysqli_result($mysqli);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

require('table.inc');
Expand All @@ -30,16 +29,16 @@ require_once('skipifconnectfailure.inc');
try {
if (!is_null($tmp = @$res->fetch_object($link, $link)))
printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
} catch (Error $e) {
handle_catchable_fatal($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}


try {
if (!is_null($tmp = @$res->fetch_object($link, $link, $link)))
printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
} catch (Error $e) {
handle_catchable_fatal($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

$obj = mysqli_fetch_object($res);
Expand Down Expand Up @@ -76,8 +75,8 @@ require_once('skipifconnectfailure.inc');

try {
$res->fetch_object('mysqli_fetch_object_construct', null);
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
mysqli_fetch_object($res);
}

Expand All @@ -88,7 +87,7 @@ require_once('skipifconnectfailure.inc');
var_dump($obj);
}
} catch (Throwable $e) {
echo "Exception: " . $e->getMessage() . "\n";
echo $e::class, ': ', $e->getMessage(), "\n";
}

$obj = $res->fetch_object('mysqli_fetch_object_construct', array('a', 'b'));
Expand All @@ -110,14 +109,14 @@ require_once('skipifconnectfailure.inc');

try {
mysqli_fetch_object($res);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
var_dump($res->fetch_object('this_class_does_not_exist'));
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

$mysqli->close();
Expand All @@ -127,14 +126,14 @@ require_once('skipifconnectfailure.inc');
<?php
require_once("clean_table.inc");
?>
--EXPECTF--
mysqli object is not fully initialized
[0] Object of class mysqli could not be converted to string in %s on line %d
[0] mysqli_result::fetch_object() expects at most 2 arguments, 3 given in %s on line %d
mysqli_result::fetch_object(): Argument #2 ($constructor_args) must be of type array, null given
Exception: Too few arguments to function mysqli_fetch_object_construct::__construct(), 1 passed and exactly 2 expected
--EXPECT--
Error: mysqli object is not fully initialized
Error: Object of class mysqli could not be converted to string
ArgumentCountError: mysqli_result::fetch_object() expects at most 2 arguments, 3 given
TypeError: mysqli_result::fetch_object(): Argument #2 ($constructor_args) must be of type array, null given
ArgumentCountError: Too few arguments to function mysqli_fetch_object_construct::__construct(), 1 passed and exactly 2 expected
NULL
NULL
mysqli_result object is already closed
mysqli_result::fetch_object(): Argument #1 ($class) must be a valid class name, this_class_does_not_exist given
Error: mysqli_result object is already closed
TypeError: mysqli_result::fetch_object(): Argument #1 ($class) must be a valid class name, this_class_does_not_exist given
done!

0 comments on commit b389846

Please sign in to comment.