Skip to content

Commit b389846

Browse files
committedJul 29, 2023
ext/mysqli: Remove catchable fatal error handler
Recoverable fatal error haven't been a thing for a while, and proper fatal error have never been catchable
1 parent 8582d97 commit b389846

File tree

3 files changed

+32
-51
lines changed

3 files changed

+32
-51
lines changed
 

‎ext/mysqli/tests/connect.inc

-16
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,3 @@
9999
}
100100
return false;
101101
}
102-
103-
function handle_catchable_fatal($errno, $error, $file, $line) {
104-
static $errcodes = array();
105-
if (empty($errcodes)) {
106-
$constants = get_defined_constants();
107-
foreach ($constants as $name => $value) {
108-
if (substr($name, 0, 2) == "E_")
109-
$errcodes[$value] = $name;
110-
}
111-
}
112-
printf("[%s] %s in %s on line %s\n",
113-
(isset($errcodes[$errno])) ? $errcodes[$errno] : $errno,
114-
$error, $file, $line);
115-
116-
return true;
117-
}

‎ext/mysqli/tests/mysqli_fetch_object.phpt

+11-13
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ require_once('skipifconnectfailure.inc');
1010
<?php
1111
include_once("connect.inc");
1212

13-
set_error_handler('handle_catchable_fatal');
14-
1513
require('table.inc');
1614
if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 5")) {
1715
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
@@ -58,7 +56,7 @@ require_once('skipifconnectfailure.inc');
5856
var_dump($obj);
5957
}
6058
} catch (Throwable $e) {
61-
echo "Exception: " . $e->getMessage() . "\n";
59+
echo $e::class, ': ', $e->getMessage(), "\n";
6260
}
6361

6462
try {
@@ -68,7 +66,7 @@ require_once('skipifconnectfailure.inc');
6866
var_dump($obj);
6967
}
7068
} catch (Throwable $e) {
71-
echo "Exception: " . $e->getMessage() . "\n";
69+
echo $e::class, ': ', $e->getMessage(), "\n";
7270
}
7371

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

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

132130
try {
133131
var_dump(mysqli_fetch_object($res, 'this_class_does_not_exist'));
134-
} catch (TypeError $e) {
135-
echo $e->getMessage(), "\n";
132+
} catch (Throwable $e) {
133+
echo $e::class, ': ', $e->getMessage(), "\n";
136134
}
137135

138136

@@ -143,12 +141,12 @@ require_once('skipifconnectfailure.inc');
143141
<?php
144142
require_once("clean_table.inc");
145143
?>
146-
--EXPECTF--
147-
Exception: Too few arguments to function mysqli_fetch_object_construct::__construct(), 0 passed and exactly 2 expected
148-
Exception: Too few arguments to function mysqli_fetch_object_construct::__construct(), 1 passed and exactly 2 expected
144+
--EXPECT--
145+
ArgumentCountError: Too few arguments to function mysqli_fetch_object_construct::__construct(), 0 passed and exactly 2 expected
146+
ArgumentCountError: Too few arguments to function mysqli_fetch_object_construct::__construct(), 1 passed and exactly 2 expected
149147
NULL
150148
NULL
151149
mysqli_result object is already closed
152-
[0] mysqli_fetch_object(): Argument #3 ($constructor_args) must be of type array, string given in %s on line %d
153-
mysqli_fetch_object(): Argument #2 ($class) must be a valid class name, this_class_does_not_exist given
150+
TypeError: mysqli_fetch_object(): Argument #3 ($constructor_args) must be of type array, string given
151+
TypeError: mysqli_fetch_object(): Argument #2 ($class) must be a valid class name, this_class_does_not_exist given
154152
done!

‎ext/mysqli/tests/mysqli_fetch_object_oo.phpt

+21-22
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ require_once('skipifconnectfailure.inc');
99
--FILE--
1010
<?php
1111
require_once("connect.inc");
12-
set_error_handler('handle_catchable_fatal');
1312

1413
$mysqli = new mysqli();
1514
try {
1615
new mysqli_result($mysqli);
17-
} catch (Error $exception) {
18-
echo $exception->getMessage() . "\n";
16+
} catch (Throwable $e) {
17+
echo $e::class, ': ', $e->getMessage(), "\n";
1918
}
2019

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

3736

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

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

7776
try {
7877
$res->fetch_object('mysqli_fetch_object_construct', null);
79-
} catch (TypeError $exception) {
80-
echo $exception->getMessage() . "\n";
78+
} catch (Throwable $e) {
79+
echo $e::class, ': ', $e->getMessage(), "\n";
8180
mysqli_fetch_object($res);
8281
}
8382

@@ -88,7 +87,7 @@ require_once('skipifconnectfailure.inc');
8887
var_dump($obj);
8988
}
9089
} catch (Throwable $e) {
91-
echo "Exception: " . $e->getMessage() . "\n";
90+
echo $e::class, ': ', $e->getMessage(), "\n";
9291
}
9392

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

111110
try {
112111
mysqli_fetch_object($res);
113-
} catch (Error $exception) {
114-
echo $exception->getMessage() . "\n";
112+
} catch (Throwable $e) {
113+
echo $e::class, ': ', $e->getMessage(), "\n";
115114
}
116115

117116
try {
118117
var_dump($res->fetch_object('this_class_does_not_exist'));
119-
} catch (TypeError $exception) {
120-
echo $exception->getMessage() . "\n";
118+
} catch (Throwable $e) {
119+
echo $e::class, ': ', $e->getMessage(), "\n";
121120
}
122121

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

0 commit comments

Comments
 (0)
Please sign in to comment.