Skip to content

Commit 8f56b7a

Browse files
kamil-tekielanikic
authored andcommitted
mysqli: Promote warning in field_seek
Aligning the behaviour of fetch_field and field_seek.
1 parent 46d22e4 commit 8f56b7a

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

ext/mysqli/mysqli_api.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -1286,9 +1286,8 @@ PHP_FUNCTION(mysqli_field_seek)
12861286
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
12871287

12881288
if ((uint32_t)fieldnr >= mysql_num_fields(result)) {
1289-
// TODO ValueError?
1290-
php_error_docref(NULL, E_WARNING, "Invalid field offset");
1291-
RETURN_FALSE;
1289+
zend_argument_value_error(ERROR_ARG_POS(2), "must be less than the number of fields for this result set");
1290+
RETURN_THROWS();
12921291
}
12931292

12941293
mysql_field_seek(result, fieldnr);

ext/mysqli/tests/mysqli_field_seek.phpt

+6-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ require_once('skipifconnectfailure.inc');
9292
}
9393

9494
var_dump(mysqli_field_tell($res));
95-
var_dump(mysqli_field_seek($res, 2));
95+
try {
96+
var_dump(mysqli_field_seek($res, 2));
97+
} catch (\ValueError $e) {
98+
echo $e->getMessage() . \PHP_EOL;
99+
}
96100
var_dump(mysqli_fetch_field($res));
97101

98102
mysqli_free_result($res);
@@ -207,9 +211,7 @@ object(stdClass)#%d (13) {
207211
int(0)
208212
}
209213
int(2)
210-
211-
Warning: mysqli_field_seek(): Invalid field offset in %s on line %d
212-
bool(false)
214+
mysqli_field_seek(): Argument #2 ($field_nr) must be less than the number of fields for this result set
213215
bool(false)
214216
bool(true)
215217
object(stdClass)#%d (13) {

ext/mysqli/tests/mysqli_field_tell.phpt

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ require_once('skipifconnectfailure.inc');
2121
var_dump(mysqli_fetch_field($res));
2222
var_dump(mysqli_field_tell($res));
2323

24-
var_dump(mysqli_field_seek($res, 2));
24+
try {
25+
var_dump(mysqli_field_seek($res, 2));
26+
} catch (\ValueError $e) {
27+
echo $e->getMessage() . \PHP_EOL;
28+
}
2529
var_dump(mysqli_field_tell($res));
2630

2731
try {
@@ -85,9 +89,7 @@ object(stdClass)#%d (13) {
8589
}
8690
bool(false)
8791
int(1)
88-
89-
Warning: mysqli_field_seek(): Invalid field offset in %s on line %d
90-
bool(false)
92+
mysqli_field_seek(): Argument #2 ($field_nr) must be less than the number of fields for this result set
9193
int(1)
9294
mysqli_field_seek(): Argument #2 ($field_nr) must be greater than or equal to 0
9395
int(1)

0 commit comments

Comments
 (0)