Skip to content

Commit 01b266a

Browse files
committed
Improve error messages of various extensions
Closes GH-5278
1 parent d7b73de commit 01b266a

29 files changed

+100
-100
lines changed

ext/bz2/bz2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static PHP_FUNCTION(bzopen)
379379
}
380380

381381
if (CHECK_ZVAL_NULL_PATH(file)) {
382-
zend_type_error("Filename must not contain null bytes");
382+
zend_argument_type_error(1, "must not contain null bytes");
383383
RETURN_THROWS();
384384
}
385385

@@ -430,7 +430,7 @@ static PHP_FUNCTION(bzopen)
430430

431431
stream = php_stream_bz2open_from_BZFILE(bz, mode, stream);
432432
} else {
433-
zend_type_error("First parameter has to be string or file-resource");
433+
zend_argument_type_error(1, "must be of type string or file-resource, %s given", zend_zval_type_name(file));
434434
RETURN_THROWS();
435435
}
436436

ext/bz2/tests/002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ resource(%d) of type (stream)
9191
resource(%d) of type (stream)
9292

9393
Warning: fopen(bz_open_002.txt): Failed to open stream: Bad file %s in %s on line %d
94-
First parameter has to be string or file-resource
94+
bzopen(): Argument #1 ($file) must be of type string or file-resource, bool given
9595

9696
Warning: fopen(bz_open_002.txt): Failed to open stream: Bad file %s in %s on line %d
97-
First parameter has to be string or file-resource
97+
bzopen(): Argument #1 ($file) must be of type string or file-resource, bool given
9898

9999
Warning: bzopen(): cannot write to a stream opened in read only mode in %s on line %d
100100
bool(false)

ext/bz2/tests/bzopen_string_filename_with_null_bytes.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ bzopen(): throw TypeError if filename contains null bytes
77

88
try {
99
bzopen("file\0", "w");
10-
} catch (\TypeError $e) {
10+
} catch (TypeError $e) {
1111
echo $e->getMessage() . \PHP_EOL;
1212
}
1313

1414
try {
1515
bzopen("file\0", "r");
16-
} catch (\TypeError $e) {
16+
} catch (TypeError $e) {
1717
echo $e->getMessage() . \PHP_EOL;
1818
}
1919

2020
?>
2121
--EXPECT--
22-
Filename must not contain null bytes
23-
Filename must not contain null bytes
22+
bzopen(): Argument #1 ($file) must not contain null bytes
23+
bzopen(): Argument #1 ($file) must not contain null bytes

ext/dom/parentnode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNod
197197
} else {
198198
xmlFree(fragment);
199199

200-
zend_type_error("Invalid argument type must be either DOMNode or string");
200+
zend_argument_type_error(i + 1, "must be of type DOMNode|string, %s given", zend_zval_type_name(&nodes[i]));
201201
return NULL;
202202
}
203203
} else if (Z_TYPE(nodes[i]) == IS_STRING) {
@@ -213,7 +213,7 @@ xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNod
213213
} else {
214214
xmlFree(fragment);
215215

216-
zend_type_error("Invalid argument type must be either DOMNode or string");
216+
zend_argument_type_error(i + 1, "must be of type DOMNode|string, %s given", zend_zval_type_name(&nodes[i]));
217217

218218
return NULL;
219219
}

ext/dom/tests/DOM4_ParentNode_append_invalidtypes.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ try {
1515
echo "OK! {$e->getMessage()}";
1616
}
1717
--EXPECT--
18-
OK! Invalid argument type must be either DOMNode or string
18+
OK! DOMElement::append(): Argument #1 must be of type DOMNode|string, array given

ext/gd/gd.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,7 +3885,7 @@ PHP_FUNCTION(imageaffine)
38853885
src = php_gd_libgdimageptr_from_zval_p(IM);
38863886

38873887
if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) {
3888-
zend_value_error("Affine array must have six elements");
3888+
zend_argument_value_error(2, "must have 6 elements");
38893889
RETURN_THROWS();
38903890
}
38913891

@@ -3902,7 +3902,7 @@ PHP_FUNCTION(imageaffine)
39023902
affine[i] = zval_get_double(zval_affine_elem);
39033903
break;
39043904
default:
3905-
zend_type_error("Invalid type for element %i", i);
3905+
zend_argument_type_error(3, "contains invalid type for element %i", i);
39063906
RETURN_THROWS();
39073907
}
39083908
}
@@ -3970,7 +3970,7 @@ PHP_FUNCTION(imageaffinematrixget)
39703970
case GD_AFFINE_SCALE: {
39713971
double x, y;
39723972
if (!options || Z_TYPE_P(options) != IS_ARRAY) {
3973-
zend_type_error("Array expected as options when using translate or scale");
3973+
zend_argument_type_error(1, "must be of type array when using translate or scale");
39743974
RETURN_THROWS();
39753975
}
39763976

@@ -4002,7 +4002,7 @@ PHP_FUNCTION(imageaffinematrixget)
40024002
double angle;
40034003

40044004
if (!options) {
4005-
zend_type_error("Number is expected as option when using rotate or shear");
4005+
zend_argument_type_error(2, "must be of type int|double when using rotate or shear");
40064006
RETURN_THROWS();
40074007
}
40084008

@@ -4019,7 +4019,7 @@ PHP_FUNCTION(imageaffinematrixget)
40194019
}
40204020

40214021
default:
4022-
zend_value_error("Invalid type for element " ZEND_LONG_FMT, type);
4022+
zend_argument_value_error(1, "must be a valid element type");
40234023
RETURN_THROWS();
40244024
}
40254025

@@ -4068,7 +4068,7 @@ PHP_FUNCTION(imageaffinematrixconcat)
40684068
m1[i] = zval_get_double(tmp);
40694069
break;
40704070
default:
4071-
zend_type_error("Matrix 1 contains invalid type for element %i", i);
4071+
zend_argument_type_error(1, "contains invalid type for element %i", i);
40724072
RETURN_THROWS();
40734073
}
40744074
}
@@ -4085,7 +4085,7 @@ PHP_FUNCTION(imageaffinematrixconcat)
40854085
m2[i] = zval_get_double(tmp);
40864086
break;
40874087
default:
4088-
zend_type_error("Matrix 2 contains invalid type for element %i", i);
4088+
zend_argument_type_error(2, "contains invalid type for element %i", i);
40894089
RETURN_THROWS();
40904090
}
40914091
}
@@ -4299,7 +4299,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
42994299
close_stream = 0;
43004300
} else if (Z_TYPE_P(to_zval) == IS_STRING) {
43014301
if (CHECK_ZVAL_NULL_PATH(to_zval)) {
4302-
zend_type_error("Invalid 2nd parameter, filename must not contain null bytes");
4302+
zend_argument_type_error(2, "must not contain null bytes");
43034303
RETURN_THROWS();
43044304
}
43054305

ext/gd/tests/bug67248.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ for($i=0;$i<7;$i++) {
1616
}
1717
?>
1818
--EXPECT--
19-
!! [TypeError] Array expected as options when using translate or scale
20-
!! [TypeError] Array expected as options when using translate or scale
21-
!! [TypeError] Number is expected as option when using rotate or shear
22-
!! [TypeError] Number is expected as option when using rotate or shear
23-
!! [TypeError] Number is expected as option when using rotate or shear
24-
!! [ValueError] Invalid type for element 5
25-
!! [ValueError] Invalid type for element 6
19+
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
20+
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
21+
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|double when using rotate or shear
22+
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|double when using rotate or shear
23+
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|double when using rotate or shear
24+
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type
25+
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type

ext/gd/tests/imagebmp_nullbyte_injection.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ try {
1515
}
1616
?>
1717
--EXPECT--
18-
Invalid 2nd parameter, filename must not contain null bytes
18+
imagebmp(): Argument #2 ($to) must not contain null bytes

ext/gd/tests/imagegif_nullbyte_injection.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ try {
1414
}
1515
?>
1616
--EXPECT--
17-
Invalid 2nd parameter, filename must not contain null bytes
17+
imagegif(): Argument #2 ($to) must not contain null bytes

ext/gd/tests/imagejpeg_nullbyte_injection.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ try {
1818
}
1919
?>
2020
--EXPECT--
21-
Invalid 2nd parameter, filename must not contain null bytes
21+
imagejpeg(): Argument #2 ($to) must not contain null bytes

0 commit comments

Comments
 (0)