Skip to content

Commit 9d983d4

Browse files
committed
Promote mysqli warnings to exceptions
1 parent 7232779 commit 9d983d4

File tree

110 files changed

+1252
-800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1252
-800
lines changed

ext/mysqli/mysqli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static MYSQLND *mysqli_convert_zv_to_mysqlnd(zval * zv)
465465
mysqli_object *intern = Z_MYSQLI_P(zv);
466466
if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
467467
/* We know that we have a mysqli object, so this failure should be emitted */
468-
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(intern->zo.ce->name));
468+
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));
469469
return NULL;
470470
}
471471
mysql = (MY_MYSQL *)(my_res->ptr);

ext/mysqli/mysqli_nonapi.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,13 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar
744744
MYSQLI_RESOURCE *my_res;
745745
mysqli_object *intern = Z_MYSQLI_P(elem);
746746
if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
747-
php_error_docref(NULL, E_WARNING, "[%d] Couldn't fetch %s", i, ZSTR_VAL(intern->zo.ce->name));
748-
continue;
747+
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));
748+
return -1;
749749
}
750750
mysql = (MY_MYSQL*) my_res->ptr;
751751
if (MYSQLI_STATUS_VALID && my_res->status < MYSQLI_STATUS_VALID) {
752-
php_error_docref(NULL, E_WARNING, "Invalid object %d or resource %s", i, ZSTR_VAL(intern->zo.ce->name));
753-
continue;
752+
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));
753+
return -1;
754754
}
755755
(*out_array)[current++] = mysql->mysql;
756756
}
@@ -859,10 +859,16 @@ PHP_FUNCTION(mysqli_poll)
859859
}
860860

861861
if (r_array != NULL) {
862-
mysqlnd_zval_array_to_mysqlnd_array(r_array, &new_r_array);
862+
if (mysqlnd_zval_array_to_mysqlnd_array(r_array, &new_r_array) == -1) {
863+
efree(new_r_array);
864+
RETURN_THROWS();
865+
}
863866
}
864867
if (e_array != NULL) {
865-
mysqlnd_zval_array_to_mysqlnd_array(e_array, &new_e_array);
868+
if (mysqlnd_zval_array_to_mysqlnd_array(e_array, &new_e_array) == -1) {
869+
efree(new_e_array);
870+
RETURN_THROWS();
871+
}
866872
}
867873

868874
ret = mysqlnd_poll(new_r_array, new_e_array, &new_dont_poll_array, sec, usec, &desc_num);

ext/mysqli/mysqli_prop.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
#define MYSQLI_GET_MYSQL(statusval) \
3838
MYSQL *p; \
3939
if (!obj->ptr || !(MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr) { \
40-
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(obj->zo.ce->name));\
41-
ZVAL_FALSE(retval);\
42-
return retval; \
40+
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name));\
41+
return NULL; \
4342
} else { \
4443
CHECK_STATUS(statusval);\
4544
p = (MYSQL *)((MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->mysql;\
@@ -48,9 +47,8 @@ if (!obj->ptr || !(MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr) { \
4847
#define MYSQLI_GET_RESULT(statusval) \
4948
MYSQL_RES *p; \
5049
if (!obj->ptr) { \
51-
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(obj->zo.ce->name));\
52-
ZVAL_NULL(retval);\
53-
return retval; \
50+
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name));\
51+
return NULL; \
5452
} else { \
5553
CHECK_STATUS(statusval);\
5654
p = (MYSQL_RES *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr; \
@@ -60,9 +58,8 @@ if (!obj->ptr) { \
6058
#define MYSQLI_GET_STMT(statusval) \
6159
MYSQL_STMT *p; \
6260
if (!obj->ptr) { \
63-
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(obj->zo.ce->name));\
64-
ZVAL_NULL(retval);\
65-
return retval; \
61+
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name));\
62+
return NULL; \
6663
} else { \
6764
CHECK_STATUS(statusval);\
6865
p = (MYSQL_STMT *)((MY_STMT *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->stmt;\

ext/mysqli/php_mysqli_structs.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,26 +246,26 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
246246
MYSQLI_RESOURCE *my_res; \
247247
mysqli_object *intern = Z_MYSQLI_P(__id); \
248248
if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {\
249-
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(intern->zo.ce->name));\
250-
RETURN_FALSE;\
249+
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));\
250+
RETURN_THROWS();\
251251
}\
252252
__ptr = (__type)my_res->ptr; \
253253
if (__check && my_res->status < __check) { \
254-
php_error_docref(NULL, E_WARNING, "invalid object or resource %s\n", ZSTR_VAL(intern->zo.ce->name)); \
255-
RETURN_FALSE;\
254+
zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(intern->zo.ce->name)); \
255+
RETURN_THROWS();\
256256
}\
257257
}
258258

259259
#define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __name, __check) \
260260
{ \
261261
MYSQLI_RESOURCE *my_res; \
262262
if (!(my_res = (MYSQLI_RESOURCE *)(__obj->ptr))) {\
263-
php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", ZSTR_VAL(intern->zo.ce->name));\
264-
return;\
265-
}\
263+
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(intern->zo.ce->name));\
264+
return;\
265+
}\
266266
__ptr = (__type)my_res->ptr; \
267267
if (__check && my_res->status < __check) { \
268-
php_error_docref(NULL, E_WARNING, "invalid object or resource %s\n", ZSTR_VAL(intern->zo.ce->name)); \
268+
zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(intern->zo.ce->name)); \
269269
return;\
270270
}\
271271
}

ext/mysqli/tests/bug28817.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ require_once('skipifconnectfailure.inc');
2222
$mysql = new my_mysql();
2323

2424
var_dump($mysql->p_test);
25-
@var_dump($mysql->errno);
25+
try {
26+
$mysql->errno;
27+
} catch (Error $exception) {
28+
echo $exception->getMessage() . "\n";
29+
}
2630

2731
$mysql->connect($host, $user, $passwd, $db, $port, $socket);
2832
$mysql->select_db("nonexistingdb");
@@ -38,5 +42,5 @@ array(2) {
3842
[1]=>
3943
%s(3) "bar"
4044
}
41-
bool(false)
45+
my_mysql object is already closed
4246
bool(true)

ext/mysqli/tests/bug36420.phpt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@ $mysqli = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
1414
$result = $mysqli->query('select 1');
1515

1616
$result->close();
17-
echo $result->num_rows;
17+
try {
18+
$result->num_rows;
19+
} catch (Error $exception) {
20+
echo $exception->getMessage() . "\n";
21+
}
1822

1923
$mysqli->close();
20-
echo $result->num_rows;
24+
try {
25+
$result->num_rows;
26+
} catch (Error $exception) {
27+
echo $exception->getMessage() . "\n";
28+
}
2129

2230
echo "Done\n";
2331
?>
2432
--EXPECTF--
25-
Warning: main(): Couldn't fetch mysqli_result in %s on line %d
26-
27-
Warning: main(): Couldn't fetch mysqli_result in %s on line %d
33+
mysqli_result object is already closed
34+
mysqli_result object is already closed
2835
Done

ext/mysqli/tests/bug36802.phpt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,35 @@ Bug #36802 (crashes with with mysqli_set_charset())
1515

1616
/* following operations should not work */
1717
if (method_exists($mysql, 'set_charset')) {
18-
$x[0] = @$mysql->set_charset('utf8');
18+
try {
19+
$mysql->set_charset('utf8');
20+
} catch (Error $exception) {
21+
echo $exception->getMessage() . "\n";
22+
}
1923
} else {
2024
$x[0] = false;
2125
}
22-
$x[1] = @$mysql->query("SELECT 'foo' FROM DUAL");
26+
27+
try {
28+
$mysql->query("SELECT 'foo' FROM DUAL");
29+
} catch (Error $exception) {
30+
echo $exception->getMessage() . "\n";
31+
}
2332

2433
/* following operations should work */
25-
$x[2] = ($mysql->client_version > 0);
26-
$x[3] = $mysql->errno;
34+
$x[1] = ($mysql->client_version > 0);
35+
$x[2] = $mysql->errno;
36+
2737
$mysql->close();
2838

2939
var_dump($x);
3040
?>
3141
--EXPECT--
32-
array(4) {
33-
[0]=>
34-
bool(false)
42+
mysqli object is not fully initialized
43+
mysqli object is not fully initialized
44+
array(2) {
3545
[1]=>
36-
bool(false)
37-
[2]=>
3846
bool(true)
39-
[3]=>
47+
[2]=>
4048
int(0)
4149
}

ext/mysqli/tests/bug63398.phpt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ mysqli_close($link);
1919
$read = $error = $reject = array();
2020
$read[] = $error[] = $reject[] = $link;
2121

22-
mysqli_poll($read, $error, $reject, 1);
22+
try {
23+
mysqli_poll($read, $error, $reject, 1);
24+
} catch (Error $exception) {
25+
echo $exception->getMessage() . "\n";
26+
}
2327

2428
echo "okey";
2529
?>
2630
--EXPECTF--
27-
Warning: mysqli_poll(): [1] Couldn't fetch mysqli in %sbug63398.php on line %d
28-
29-
Warning: mysqli_poll(): [1] Couldn't fetch mysqli in %sbug63398.php on line %d
30-
31-
Warning: mysqli_poll(): No stream arrays were passed in %sbug63398.php on line %d
32-
33-
Warning: mysqli_poll(): [1] Couldn't fetch mysqli in %sbug63398.php on line %d
34-
35-
Warning: mysqli_poll(): [1] Couldn't fetch mysqli in %sbug63398.php on line %d
31+
mysqli object is already closed
3632
okey

ext/mysqli/tests/bug73462.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ require_once('skipifconnectfailure.inc');
1919

2020
/* Failed connection to invalid host */
2121
$mysql_2 = @new mysqli(' !!! invalid !!! ', $user, $passwd, $db);
22-
@$mysql_2->close();
22+
try {
23+
$mysql_2->close();
24+
} catch (Error $exception) {
25+
echo $exception->getMessage() . "\n";
26+
}
2327

2428
/* Re-use persistent connection */
2529
$mysql_3 = new mysqli('p:'.$host, $user, $passwd, $db);
@@ -38,4 +42,5 @@ require_once('skipifconnectfailure.inc');
3842
print "done!";
3943
?>
4044
--EXPECT--
45+
mysqli object is already closed
4146
done!

ext/mysqli/tests/bug75448.phpt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ require_once('skipifconnectfailure.inc');
1111
require_once 'connect.inc';
1212
$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket);
1313
mysqli_close($link);
14-
$stmt = mysqli_prepare($link, 'SELECT VERSION()');
15-
var_dump($stmt);
16-
?>
17-
--EXPECTF--
18-
Warning: mysqli_prepare(): Couldn't fetch mysqli in %s on line %d
19-
bool(false)
14+
15+
try {
16+
mysqli_prepare($link, 'SELECT VERSION()');
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
20+
--EXPECT--
21+
mysqli object is already closed

0 commit comments

Comments
 (0)