Skip to content

Commit c19c380

Browse files
committed
Promote incorrect bzerr stream type to TypeError
This restores the signature we originally promised for PHP-8.0, without the spurious false return type.
1 parent 543bc88 commit c19c380

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

ext/bz2/bz2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt)
578578
php_stream_from_zval(stream, bzp);
579579

580580
if (!php_stream_is(stream, PHP_STREAM_IS_BZIP2)) {
581-
php_error_docref(NULL, E_WARNING, "Stream is not a bz2 stream");
582-
RETURN_FALSE;
581+
zend_argument_type_error(1, "must be a bz2 stream");
582+
RETURN_THROWS();
583583
}
584584

585585
self = (struct php_bz2_stream_data_t *) stream->abstract;

ext/bz2/bz2.stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ function bzflush($bz): bool {}
3333
function bzclose($bz): bool {}
3434

3535
/** @param resource $bz */
36-
function bzerrno($bz): int|false {}
36+
function bzerrno($bz): int {}
3737

3838
/** @param resource $bz */
39-
function bzerrstr($bz): string|false {}
39+
function bzerrstr($bz): string {}
4040

4141
/** @param resource $bz */
42-
function bzerror($bz): array|false {}
42+
function bzerror($bz): array {}
4343

4444
function bzcompress(string $data, int $block_size = 4, int $work_factor = 0): string|int {}
4545

ext/bz2/bz2_arginfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: fd2fbdf27def51022e890fe1634a9ce2ebba643a */
2+
* Stub hash: 8116780e328f137ca15ae445c9d6b45cf2f41f06 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_bzopen, 0, 0, 2)
55
ZEND_ARG_INFO(0, file)
@@ -23,15 +23,15 @@ ZEND_END_ARG_INFO()
2323

2424
#define arginfo_bzclose arginfo_bzflush
2525

26-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzerrno, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
26+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bzerrno, 0, 1, IS_LONG, 0)
2727
ZEND_ARG_INFO(0, bz)
2828
ZEND_END_ARG_INFO()
2929

30-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzerrstr, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
30+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bzerrstr, 0, 1, IS_STRING, 0)
3131
ZEND_ARG_INFO(0, bz)
3232
ZEND_END_ARG_INFO()
3333

34-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzerror, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
34+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bzerror, 0, 1, IS_ARRAY, 0)
3535
ZEND_ARG_INFO(0, bz)
3636
ZEND_END_ARG_INFO()
3737

ext/bz2/tests/bzerr_functions_on_invalid_stream.phpt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ Calling bzerr* functions on non-bz2 streams
55
--FILE--
66
<?php
77
$f = fopen(__FILE__, 'r');
8-
var_dump(bzerrno($f));
9-
var_dump(bzerrstr($f));
10-
var_dump(bzerror($f));
8+
try {
9+
var_dump(bzerrno($f));
10+
} catch (TypeError $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
try {
14+
var_dump(bzerrstr($f));
15+
} catch (TypeError $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
try {
19+
var_dump(bzerror($f));
20+
} catch (TypeError $e) {
21+
echo $e->getMessage(), "\n";
22+
}
1123
?>
12-
--EXPECTF--
13-
Warning: bzerrno(): Stream is not a bz2 stream in %s on line %d
14-
bool(false)
15-
16-
Warning: bzerrstr(): Stream is not a bz2 stream in %s on line %d
17-
bool(false)
18-
19-
Warning: bzerror(): Stream is not a bz2 stream in %s on line %d
20-
bool(false)
24+
--EXPECT--
25+
bzerrno(): Argument #1 ($bz) must be a bz2 stream
26+
bzerrstr(): Argument #1 ($bz) must be a bz2 stream
27+
bzerror(): Argument #1 ($bz) must be a bz2 stream

0 commit comments

Comments
 (0)