Skip to content

Declare tentative return types for ext/standard #7065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/bug21478.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bug #21478 (Zend/zend_alloc.c :: shutdown_memory_manager produces segfault)
--FILE--
<?php
class debugfilter extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = strtoupper($bucket->data);
stream_bucket_append($out, $bucket);
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug78406.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (!class_exists(SampleFilter::class)) {
{
private $data = '';

public function filter($in, $out, &$consumed, $closing)
public function filter($in, $out, &$consumed, $closing): int
{
while ($bucket = stream_bucket_make_writeable($in))
{
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/tests/bug64353.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ opcache
--FILE--
<?php
class BugLoader extends php_user_filter {
public function filter($in, $out, &$consumed, $closing) {
public function filter($in, $out, &$consumed, $closing): int {
if (!class_exists("Test")) {
eval("class Test extends ArrayObject {}");
}
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/tests/bug74596.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ file_put_contents(__DIR__ . "/bug74596_2.php", "ok\n");

class ufilter extends php_user_filter
{
function filter($in, $out, &$consumed, $closing)
function filter($in, $out, &$consumed, $closing): int
{
include_once __DIR__ . "/bug74596_1.php";
while ($bucket = stream_bucket_make_writeable($in)) {
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/tests/jit/reg_alloc_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Caster
const EXCLUDE_PRIVATE = 32;
const EXCLUDE_STRICT = 512;

public static function filter(array $a, $filter)
public static function filter(array $a, $filter): int
{
foreach ($a as $k => $v) {
if (!isset($k[1])) {
Expand Down
12 changes: 6 additions & 6 deletions ext/standard/dir.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
class Directory
{
/**
* @return void
* @tentative-return-type
* @implementation-alias closedir
*/
public function close() {}
public function close(): void {}

/**
* @return void
* @tentative-return-type
* @implementation-alias rewinddir
*/
public function rewind() {}
public function rewind(): void {}

/**
* @return string|false
* @tentative-return-type
* @implementation-alias readdir
*/
public function read() {}
public function read(): string|false {}
}
7 changes: 4 additions & 3 deletions ext/standard/dir_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 1fd5cc5147c7272006e59d63d68c12caec84589f */
* Stub hash: e3d46788bb18dc90a0922e5738442b2932dd53f6 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Directory_close, 0, 0, 0)
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Directory_close, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_Directory_rewind arginfo_class_Directory_close

#define arginfo_class_Directory_read arginfo_class_Directory_close
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_Directory_read, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_END_ARG_INFO()


ZEND_FUNCTION(closedir);
Expand Down
3 changes: 3 additions & 0 deletions ext/standard/tests/directory/DirectoryClass_basic_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ Class [ <internal%s> class Directory ] {

- Parameters [0] {
}
- Tentative return [ void ]
}

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

- Parameters [0] {
}
- Tentative return [ void ]
}

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

- Parameters [0] {
}
- Tentative return [ string|false ]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/file/bug39551.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Bug #39551 (Segfault with stream_bucket_new in user filter)
$bucket = stream_bucket_new(fopen('php://temp', 'w+'), '');

class bucketFilter {
public function filter($in, $out, &$consumed, $closing ){
public function filter($in, $out, &$consumed, $closing ): int {

$bucket = stream_bucket_new(fopen('php://temp', 'w+'), '');
stream_bucket_append($out, $bucket);
Expand Down
5 changes: 3 additions & 2 deletions ext/standard/tests/file/userfilters.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stream userfilter test
<?php

class testfilter extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = strtoupper($bucket->data);
$consumed += strlen($bucket->data);
Expand All @@ -13,8 +13,9 @@ class testfilter extends php_user_filter {
return PSFS_PASS_ON;
}

function oncreate() {
function oncreate(): bool {
echo "params: {$this->params}\n";
return true;
}
}

Expand Down
17 changes: 10 additions & 7 deletions ext/standard/tests/filters/bug35916.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ $file = __DIR__ . "/bug35916.txt";

class strtoupper_filter extends php_user_filter
{
function filter($in, $out, &$consumed, $closing)
{
while($bucket=stream_bucket_make_writeable($in)) {
function filter($in, $out, &$consumed, $closing): int
{
while ($bucket=stream_bucket_make_writeable($in)) {
$bucket->data = strtoupper($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
function onCreate()
return PSFS_PASS_ON;
}

function onCreate(): bool
{
echo "fffffffffff\n";
return true;
}
function onClose()

function onClose(): void
{
echo "hello\n";
}
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/filters/bug46164-1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bug #46164 - 1 (stream_filter_remove() closes the stream)
--FILE--
<?php
class user_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
while($bucket = stream_bucket_make_writeable($in)) {
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/filters/bug46164-2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bug #46164 - 2 (stream_filter_remove() closes the stream)
--FILE--
<?php
class user_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
while($bucket = stream_bucket_make_writeable($in)) {
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/filters/bug72941.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bug #72941 (Modifying bucket->data by-ref has no effect any longer)
<?php
class rotate_filter_nw extends php_user_filter
{
function filter($in, $out, &$consumed, $closing)
function filter($in, $out, &$consumed, $closing): int
{
while ($bucket = stream_bucket_make_writeable($in)) {
$this->rotate($bucket->data);
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/filters/bug73586.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bug #73586 (php_user_filter::$stream is not set to the stream the filter is work
<?php
class append_filter extends php_user_filter {
public $stream;
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
while ($bucket = stream_bucket_make_writeable($in)) {
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
Expand All @@ -25,7 +25,7 @@ stream_copy_to_stream($fin, STDOUT);
<?php
class append_filter extends php_user_filter {
public $stream;
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
while ($bucket = stream_bucket_make_writeable($in)) {
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
Expand Down
10 changes: 5 additions & 5 deletions ext/standard/tests/filters/filter_errors_user.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ Filter errors: user filter
require 'filter_errors.inc';

class test_filter0 extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
return PSFS_ERR_FATAL;
}
}
class test_filter1 extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
$bucket = stream_bucket_make_writeable($in);
return PSFS_ERR_FATAL;
}
}
class test_filter2 extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
while ($bucket = stream_bucket_make_writeable($in)) {
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
Expand All @@ -25,7 +25,7 @@ class test_filter2 extends php_user_filter {
}
}
class test_filter3 extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
if (!$closing) {
$bucket = stream_bucket_new($this->stream, "42");
stream_bucket_append($out, $bucket);
Expand All @@ -34,7 +34,7 @@ class test_filter3 extends php_user_filter {
}
}
class test_filter4 extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
if (!$closing) {
$bucket = stream_bucket_new($this->stream, "42");
}
Expand Down
14 changes: 7 additions & 7 deletions ext/standard/tests/filters/php_user_filter_01.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ class php_user_filter#1
--FILE--
<?php
class foo extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {}
function onCreate() {}
function onClose() {}
function filter($in, $out, &$consumed, $closing): int {}
function onCreate(): bool {}
function onClose(): void {}
}
class bar extends php_user_filter {
function filter($in, $out, &$consumed) {}
function onCreate() {}
function onClose() {}
function filter($in, $out, &$consumed): int {}
function onCreate(): bool {}
function onClose(): void {}
}
?>
--EXPECTF--
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
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
8 changes: 4 additions & 4 deletions ext/standard/tests/filters/php_user_filter_02.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ class php_user_filter#2
--FILE--
<?php
class foo extends php_user_filter {
function filter($in, $out, $consumed, $closing) {}
function onCreate() {}
function onClose() {}
function filter($in, $out, $consumed, $closing): int {}
function onCreate(): bool {}
function onClose(): void {}
}
?>
--EXPECTF--
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
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
8 changes: 4 additions & 4 deletions ext/standard/tests/filters/php_user_filter_03.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ class php_user_filter#3
--FILE--
<?php
class foo extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {}
function onCreate($var) {}
function onClose() {}
function filter($in, $out, &$consumed, $closing): int {}
function onCreate($var): bool {}
function onClose(): void {}
}
?>
--EXPECTF--
Fatal error: Declaration of foo::onCreate($var) must be compatible with php_user_filter::onCreate() in %s on line %d
Fatal error: Declaration of foo::onCreate($var): bool must be compatible with php_user_filter::onCreate(): bool in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ php_user_filter onCreate() returns false
<?php

class my_filter extends php_user_filter {
function onCreate() {
function onCreate(): bool {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/filters/read.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stream filter - reading
<?php
echo "-TEST\n";
class strtoupper_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing)
function filter($in, $out, &$consumed, $closing): int
{
$output = 0;
while ($bucket = stream_bucket_make_writeable($in)) {
Expand Down Expand Up @@ -38,7 +38,7 @@ echo "Done\n";
<?PHP
ECHO "-TEST\N";
CLASS STRTOUPPER_FILTER EXTENDS PHP_USER_FILTER {
FUNCTION FILTER($IN, $OUT, &$CONSUMED, $CLOSING)
FUNCTION FILTER($IN, $OUT, &$CONSUMED, $CLOSING): INT
{
$OUTPUT = 0;
WHILE ($BUCKET = STREAM_BUCKET_MAKE_WRITEABLE($IN)) {
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/streams/bug77069.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bug #77069 (stream filter loses final block of data)
class MyFilter extends php_user_filter {
private $data = '';

public function filter($in, $out, &$consumed, $closing) {
public function filter($in, $out, &$consumed, $closing): int {
$return = PSFS_FEED_ME;

// While input data is available, continue to read it.
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/streams/bug78506.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bug #78506: Error in a php_user_filter::filter() is not reported
<?php

class MyFilter extends php_user_filter {
public function filter($in, $out, &$consumed, $closing)
public function filter($in, $out, &$consumed, $closing): int
{
stream_bucket_make_writeable($in);
return PSFS_ERR_FATAL;
Expand Down
6 changes: 3 additions & 3 deletions ext/standard/tests/streams/bug79984.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ Bug #79984 (Stream filter is not called with closing arg)

class F extends php_user_filter
{
public function onCreate()
public function onCreate(): bool
{
echo 'filter onCreate' . PHP_EOL;
return true;
}

public function onClose()
public function onClose(): void
{
echo 'filter onClose' . PHP_EOL;
}

public function filter($in, $out, &$consumed, $closing)
public function filter($in, $out, &$consumed, $closing): int
{
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = strtoupper($bucket->data);
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/streams/stream_filter_register.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ User Group: PHP-WVL & PHPGent #PHPTestFest
--FILE--
<?php
class foo extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
}
}

class bar extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
function filter($in, $out, &$consumed, $closing): int {
}
}

Expand Down
Loading