Promote incorrect bzerr stream type to TypeError

This restores the signature we originally promised for PHP-8.0,
without the spurious false return type.
This commit is contained in:
Nikita Popov 2021-11-05 11:13:08 +01:00
parent 543bc88646
commit c19c380323
4 changed files with 28 additions and 21 deletions

View File

@ -578,8 +578,8 @@ static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt)
php_stream_from_zval(stream, bzp);
if (!php_stream_is(stream, PHP_STREAM_IS_BZIP2)) {
php_error_docref(NULL, E_WARNING, "Stream is not a bz2 stream");
RETURN_FALSE;
zend_argument_type_error(1, "must be a bz2 stream");
RETURN_THROWS();
}
self = (struct php_bz2_stream_data_t *) stream->abstract;

View File

@ -33,13 +33,13 @@ function bzflush($bz): bool {}
function bzclose($bz): bool {}
/** @param resource $bz */
function bzerrno($bz): int|false {}
function bzerrno($bz): int {}
/** @param resource $bz */
function bzerrstr($bz): string|false {}
function bzerrstr($bz): string {}
/** @param resource $bz */
function bzerror($bz): array|false {}
function bzerror($bz): array {}
function bzcompress(string $data, int $block_size = 4, int $work_factor = 0): string|int {}

View File

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: fd2fbdf27def51022e890fe1634a9ce2ebba643a */
* Stub hash: 8116780e328f137ca15ae445c9d6b45cf2f41f06 */
ZEND_BEGIN_ARG_INFO_EX(arginfo_bzopen, 0, 0, 2)
ZEND_ARG_INFO(0, file)
@ -23,15 +23,15 @@ ZEND_END_ARG_INFO()
#define arginfo_bzclose arginfo_bzflush
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzerrno, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bzerrno, 0, 1, IS_LONG, 0)
ZEND_ARG_INFO(0, bz)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzerrstr, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bzerrstr, 0, 1, IS_STRING, 0)
ZEND_ARG_INFO(0, bz)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bzerror, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bzerror, 0, 1, IS_ARRAY, 0)
ZEND_ARG_INFO(0, bz)
ZEND_END_ARG_INFO()

View File

@ -5,16 +5,23 @@ Calling bzerr* functions on non-bz2 streams
--FILE--
<?php
$f = fopen(__FILE__, 'r');
var_dump(bzerrno($f));
var_dump(bzerrstr($f));
var_dump(bzerror($f));
try {
var_dump(bzerrno($f));
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(bzerrstr($f));
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(bzerror($f));
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Warning: bzerrno(): Stream is not a bz2 stream in %s on line %d
bool(false)
Warning: bzerrstr(): Stream is not a bz2 stream in %s on line %d
bool(false)
Warning: bzerror(): Stream is not a bz2 stream in %s on line %d
bool(false)
--EXPECT--
bzerrno(): Argument #1 ($bz) must be a bz2 stream
bzerrstr(): Argument #1 ($bz) must be a bz2 stream
bzerror(): Argument #1 ($bz) must be a bz2 stream