Skip to content

Commit 48981f4

Browse files
authored
Declare tentative return types for ext/standard (php#7065)
1 parent 0b01d58 commit 48981f4

29 files changed

+81
-72
lines changed

Zend/tests/bug21478.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bug #21478 (Zend/zend_alloc.c :: shutdown_memory_manager produces segfault)
33
--FILE--
44
<?php
55
class debugfilter extends php_user_filter {
6-
function filter($in, $out, &$consumed, $closing) {
6+
function filter($in, $out, &$consumed, $closing): int {
77
while ($bucket = stream_bucket_make_writeable($in)) {
88
$bucket->data = strtoupper($bucket->data);
99
stream_bucket_append($out, $bucket);

Zend/tests/bug78406.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (!class_exists(SampleFilter::class)) {
1010
{
1111
private $data = '';
1212

13-
public function filter($in, $out, &$consumed, $closing)
13+
public function filter($in, $out, &$consumed, $closing): int
1414
{
1515
while ($bucket = stream_bucket_make_writeable($in))
1616
{

ext/opcache/tests/bug64353.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ opcache
99
--FILE--
1010
<?php
1111
class BugLoader extends php_user_filter {
12-
public function filter($in, $out, &$consumed, $closing) {
12+
public function filter($in, $out, &$consumed, $closing): int {
1313
if (!class_exists("Test")) {
1414
eval("class Test extends ArrayObject {}");
1515
}

ext/opcache/tests/bug74596.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ file_put_contents(__DIR__ . "/bug74596_2.php", "ok\n");
3232

3333
class ufilter extends php_user_filter
3434
{
35-
function filter($in, $out, &$consumed, $closing)
35+
function filter($in, $out, &$consumed, $closing): int
3636
{
3737
include_once __DIR__ . "/bug74596_1.php";
3838
while ($bucket = stream_bucket_make_writeable($in)) {

ext/opcache/tests/jit/reg_alloc_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Caster
1616
const EXCLUDE_PRIVATE = 32;
1717
const EXCLUDE_STRICT = 512;
1818

19-
public static function filter(array $a, $filter)
19+
public static function filter(array $a, $filter): int
2020
{
2121
foreach ($a as $k => $v) {
2222
if (!isset($k[1])) {

ext/standard/dir.stub.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
class Directory
66
{
77
/**
8-
* @return void
8+
* @tentative-return-type
99
* @implementation-alias closedir
1010
*/
11-
public function close() {}
11+
public function close(): void {}
1212

1313
/**
14-
* @return void
14+
* @tentative-return-type
1515
* @implementation-alias rewinddir
1616
*/
17-
public function rewind() {}
17+
public function rewind(): void {}
1818

1919
/**
20-
* @return string|false
20+
* @tentative-return-type
2121
* @implementation-alias readdir
2222
*/
23-
public function read() {}
23+
public function read(): string|false {}
2424
}

ext/standard/dir_arginfo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 1fd5cc5147c7272006e59d63d68c12caec84589f */
2+
* Stub hash: e3d46788bb18dc90a0922e5738442b2932dd53f6 */
33

4-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Directory_close, 0, 0, 0)
4+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Directory_close, 0, 0, IS_VOID, 0)
55
ZEND_END_ARG_INFO()
66

77
#define arginfo_class_Directory_rewind arginfo_class_Directory_close
88

9-
#define arginfo_class_Directory_read arginfo_class_Directory_close
9+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_Directory_read, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
10+
ZEND_END_ARG_INFO()
1011

1112

1213
ZEND_FUNCTION(closedir);

ext/standard/tests/directory/DirectoryClass_basic_001.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,21 @@ Class [ <internal%s> class Directory ] {
4343

4444
- Parameters [0] {
4545
}
46+
- Tentative return [ void ]
4647
}
4748

4849
Method [ <internal:standard> public method rewind ] {
4950

5051
- Parameters [0] {
5152
}
53+
- Tentative return [ void ]
5254
}
5355

5456
Method [ <internal:standard> public method read ] {
5557

5658
- Parameters [0] {
5759
}
60+
- Tentative return [ string|false ]
5861
}
5962
}
6063
}

ext/standard/tests/file/bug39551.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Bug #39551 (Segfault with stream_bucket_new in user filter)
66
$bucket = stream_bucket_new(fopen('php://temp', 'w+'), '');
77

88
class bucketFilter {
9-
public function filter($in, $out, &$consumed, $closing ){
9+
public function filter($in, $out, &$consumed, $closing ): int {
1010

1111
$bucket = stream_bucket_new(fopen('php://temp', 'w+'), '');
1212
stream_bucket_append($out, $bucket);

ext/standard/tests/file/userfilters.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ stream userfilter test
44
<?php
55

66
class testfilter extends php_user_filter {
7-
function filter($in, $out, &$consumed, $closing) {
7+
function filter($in, $out, &$consumed, $closing): int {
88
while ($bucket = stream_bucket_make_writeable($in)) {
99
$bucket->data = strtoupper($bucket->data);
1010
$consumed += strlen($bucket->data);
@@ -13,8 +13,9 @@ class testfilter extends php_user_filter {
1313
return PSFS_PASS_ON;
1414
}
1515

16-
function oncreate() {
16+
function oncreate(): bool {
1717
echo "params: {$this->params}\n";
18+
return true;
1819
}
1920
}
2021

ext/standard/tests/filters/bug35916.phpt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ $file = __DIR__ . "/bug35916.txt";
77

88
class strtoupper_filter extends php_user_filter
99
{
10-
function filter($in, $out, &$consumed, $closing)
11-
{
12-
while($bucket=stream_bucket_make_writeable($in)) {
10+
function filter($in, $out, &$consumed, $closing): int
11+
{
12+
while ($bucket=stream_bucket_make_writeable($in)) {
1313
$bucket->data = strtoupper($bucket->data);
1414
$consumed += $bucket->datalen;
1515
stream_bucket_append($out, $bucket);
1616
stream_bucket_append($out, $bucket);
17-
}
18-
return PSFS_PASS_ON;
1917
}
20-
function onCreate()
18+
return PSFS_PASS_ON;
19+
}
20+
21+
function onCreate(): bool
2122
{
2223
echo "fffffffffff\n";
24+
return true;
2325
}
24-
function onClose()
26+
27+
function onClose(): void
2528
{
2629
echo "hello\n";
2730
}

ext/standard/tests/filters/bug46164-1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bug #46164 - 1 (stream_filter_remove() closes the stream)
33
--FILE--
44
<?php
55
class user_filter extends php_user_filter {
6-
function filter($in, $out, &$consumed, $closing) {
6+
function filter($in, $out, &$consumed, $closing): int {
77
while($bucket = stream_bucket_make_writeable($in)) {
88
$consumed += $bucket->datalen;
99
stream_bucket_append($out, $bucket);

ext/standard/tests/filters/bug46164-2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bug #46164 - 2 (stream_filter_remove() closes the stream)
33
--FILE--
44
<?php
55
class user_filter extends php_user_filter {
6-
function filter($in, $out, &$consumed, $closing) {
6+
function filter($in, $out, &$consumed, $closing): int {
77
while($bucket = stream_bucket_make_writeable($in)) {
88
$consumed += $bucket->datalen;
99
stream_bucket_append($out, $bucket);

ext/standard/tests/filters/bug72941.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Bug #72941 (Modifying bucket->data by-ref has no effect any longer)
44
<?php
55
class rotate_filter_nw extends php_user_filter
66
{
7-
function filter($in, $out, &$consumed, $closing)
7+
function filter($in, $out, &$consumed, $closing): int
88
{
99
while ($bucket = stream_bucket_make_writeable($in)) {
1010
$this->rotate($bucket->data);

ext/standard/tests/filters/bug73586.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Bug #73586 (php_user_filter::$stream is not set to the stream the filter is work
44
<?php
55
class append_filter extends php_user_filter {
66
public $stream;
7-
function filter($in, $out, &$consumed, $closing) {
7+
function filter($in, $out, &$consumed, $closing): int {
88
while ($bucket = stream_bucket_make_writeable($in)) {
99
$consumed += $bucket->datalen;
1010
stream_bucket_append($out, $bucket);
@@ -25,7 +25,7 @@ stream_copy_to_stream($fin, STDOUT);
2525
<?php
2626
class append_filter extends php_user_filter {
2727
public $stream;
28-
function filter($in, $out, &$consumed, $closing) {
28+
function filter($in, $out, &$consumed, $closing): int {
2929
while ($bucket = stream_bucket_make_writeable($in)) {
3030
$consumed += $bucket->datalen;
3131
stream_bucket_append($out, $bucket);

ext/standard/tests/filters/filter_errors_user.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ Filter errors: user filter
55
require 'filter_errors.inc';
66

77
class test_filter0 extends php_user_filter {
8-
function filter($in, $out, &$consumed, $closing) {
8+
function filter($in, $out, &$consumed, $closing): int {
99
return PSFS_ERR_FATAL;
1010
}
1111
}
1212
class test_filter1 extends php_user_filter {
13-
function filter($in, $out, &$consumed, $closing) {
13+
function filter($in, $out, &$consumed, $closing): int {
1414
$bucket = stream_bucket_make_writeable($in);
1515
return PSFS_ERR_FATAL;
1616
}
1717
}
1818
class test_filter2 extends php_user_filter {
19-
function filter($in, $out, &$consumed, $closing) {
19+
function filter($in, $out, &$consumed, $closing): int {
2020
while ($bucket = stream_bucket_make_writeable($in)) {
2121
$consumed += $bucket->datalen;
2222
stream_bucket_append($out, $bucket);
@@ -25,7 +25,7 @@ class test_filter2 extends php_user_filter {
2525
}
2626
}
2727
class test_filter3 extends php_user_filter {
28-
function filter($in, $out, &$consumed, $closing) {
28+
function filter($in, $out, &$consumed, $closing): int {
2929
if (!$closing) {
3030
$bucket = stream_bucket_new($this->stream, "42");
3131
stream_bucket_append($out, $bucket);
@@ -34,7 +34,7 @@ class test_filter3 extends php_user_filter {
3434
}
3535
}
3636
class test_filter4 extends php_user_filter {
37-
function filter($in, $out, &$consumed, $closing) {
37+
function filter($in, $out, &$consumed, $closing): int {
3838
if (!$closing) {
3939
$bucket = stream_bucket_new($this->stream, "42");
4040
}

ext/standard/tests/filters/php_user_filter_01.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ class php_user_filter#1
33
--FILE--
44
<?php
55
class foo extends php_user_filter {
6-
function filter($in, $out, &$consumed, $closing) {}
7-
function onCreate() {}
8-
function onClose() {}
6+
function filter($in, $out, &$consumed, $closing): int {}
7+
function onCreate(): bool {}
8+
function onClose(): void {}
99
}
1010
class bar extends php_user_filter {
11-
function filter($in, $out, &$consumed) {}
12-
function onCreate() {}
13-
function onClose() {}
11+
function filter($in, $out, &$consumed): int {}
12+
function onCreate(): bool {}
13+
function onClose(): void {}
1414
}
1515
?>
1616
--EXPECTF--
17-
Fatal error: Declaration of bar::filter($in, $out, &$consumed) must be compatible with php_user_filter::filter($in, $out, &$consumed, bool $closing) in %s on line %d
17+
Fatal error: Declaration of bar::filter($in, $out, &$consumed): int must be compatible with php_user_filter::filter($in, $out, &$consumed, bool $closing): int in %s on line %d

ext/standard/tests/filters/php_user_filter_02.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ class php_user_filter#2
33
--FILE--
44
<?php
55
class foo extends php_user_filter {
6-
function filter($in, $out, $consumed, $closing) {}
7-
function onCreate() {}
8-
function onClose() {}
6+
function filter($in, $out, $consumed, $closing): int {}
7+
function onCreate(): bool {}
8+
function onClose(): void {}
99
}
1010
?>
1111
--EXPECTF--
12-
Fatal error: Declaration of foo::filter($in, $out, $consumed, $closing) must be compatible with php_user_filter::filter($in, $out, &$consumed, bool $closing) in %s on line %d
12+
Fatal error: Declaration of foo::filter($in, $out, $consumed, $closing): int must be compatible with php_user_filter::filter($in, $out, &$consumed, bool $closing): int in %s on line %d

ext/standard/tests/filters/php_user_filter_03.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ class php_user_filter#3
33
--FILE--
44
<?php
55
class foo extends php_user_filter {
6-
function filter($in, $out, &$consumed, $closing) {}
7-
function onCreate($var) {}
8-
function onClose() {}
6+
function filter($in, $out, &$consumed, $closing): int {}
7+
function onCreate($var): bool {}
8+
function onClose(): void {}
99
}
1010
?>
1111
--EXPECTF--
12-
Fatal error: Declaration of foo::onCreate($var) must be compatible with php_user_filter::onCreate() in %s on line %d
12+
Fatal error: Declaration of foo::onCreate($var): bool must be compatible with php_user_filter::onCreate(): bool in %s on line %d

ext/standard/tests/filters/php_user_filter_onCreate_failure.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ php_user_filter onCreate() returns false
44
<?php
55

66
class my_filter extends php_user_filter {
7-
function onCreate() {
7+
function onCreate(): bool {
88
return false;
99
}
1010
}

ext/standard/tests/filters/read.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ stream filter - reading
44
<?php
55
echo "-TEST\n";
66
class strtoupper_filter extends php_user_filter {
7-
function filter($in, $out, &$consumed, $closing)
7+
function filter($in, $out, &$consumed, $closing): int
88
{
99
$output = 0;
1010
while ($bucket = stream_bucket_make_writeable($in)) {
@@ -38,7 +38,7 @@ echo "Done\n";
3838
<?PHP
3939
ECHO "-TEST\N";
4040
CLASS STRTOUPPER_FILTER EXTENDS PHP_USER_FILTER {
41-
FUNCTION FILTER($IN, $OUT, &$CONSUMED, $CLOSING)
41+
FUNCTION FILTER($IN, $OUT, &$CONSUMED, $CLOSING): INT
4242
{
4343
$OUTPUT = 0;
4444
WHILE ($BUCKET = STREAM_BUCKET_MAKE_WRITEABLE($IN)) {

ext/standard/tests/streams/bug77069.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bug #77069 (stream filter loses final block of data)
55
class MyFilter extends php_user_filter {
66
private $data = '';
77

8-
public function filter($in, $out, &$consumed, $closing) {
8+
public function filter($in, $out, &$consumed, $closing): int {
99
$return = PSFS_FEED_ME;
1010

1111
// While input data is available, continue to read it.

ext/standard/tests/streams/bug78506.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Bug #78506: Error in a php_user_filter::filter() is not reported
44
<?php
55

66
class MyFilter extends php_user_filter {
7-
public function filter($in, $out, &$consumed, $closing)
7+
public function filter($in, $out, &$consumed, $closing): int
88
{
99
stream_bucket_make_writeable($in);
1010
return PSFS_ERR_FATAL;

ext/standard/tests/streams/bug79984.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ Bug #79984 (Stream filter is not called with closing arg)
55

66
class F extends php_user_filter
77
{
8-
public function onCreate()
8+
public function onCreate(): bool
99
{
1010
echo 'filter onCreate' . PHP_EOL;
1111
return true;
1212
}
1313

14-
public function onClose()
14+
public function onClose(): void
1515
{
1616
echo 'filter onClose' . PHP_EOL;
1717
}
1818

19-
public function filter($in, $out, &$consumed, $closing)
19+
public function filter($in, $out, &$consumed, $closing): int
2020
{
2121
while ($bucket = stream_bucket_make_writeable($in)) {
2222
$bucket->data = strtoupper($bucket->data);

ext/standard/tests/streams/stream_filter_register.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ User Group: PHP-WVL & PHPGent #PHPTestFest
66
--FILE--
77
<?php
88
class foo extends php_user_filter {
9-
function filter($in, $out, &$consumed, $closing) {
9+
function filter($in, $out, &$consumed, $closing): int {
1010
}
1111
}
1212

1313
class bar extends php_user_filter {
14-
function filter($in, $out, &$consumed, $closing) {
14+
function filter($in, $out, &$consumed, $closing): int {
1515
}
1616
}
1717

0 commit comments

Comments
 (0)