Skip to content

Commit a594b89

Browse files
committed
Declare tentative return types for Zend
1 parent edb6b37 commit a594b89

File tree

119 files changed

+559
-540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+559
-540
lines changed

Zend/tests/ArrayAccess_indirect_append.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ Using indirect append on ArrayAccess object
55

66
class AA implements ArrayAccess {
77
private $data = [];
8-
public function &offsetGet($name) {
8+
public function &offsetGet($name): mixed {
99
if (null === $name) {
1010
return $this->data[];
1111
} else {
1212
return $this->data[$name];
1313
}
1414
}
15-
public function offsetSet($name, $value) {
15+
public function offsetSet($name, $value): void {
1616
$this->data[$name] = $value;
1717
}
18-
public function offsetUnset($name) {}
19-
public function offsetExists($name) {}
18+
public function offsetUnset($name): void {}
19+
public function offsetExists($name): bool {}
2020
}
2121

2222
$aa = new AA;

Zend/tests/anon/004.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ class Outer {
1212
public function getArrayAccess() {
1313
/* create a proxy object implementing array access */
1414
return new class($this->data) extends Outer implements ArrayAccess {
15-
public function offsetGet($offset) { return $this->data[$offset]; }
16-
public function offsetSet($offset, $data) { return ($this->data[$offset] = $data); }
17-
public function offsetUnset($offset) { unset($this->data[$offset]); }
18-
public function offsetExists($offset) { return isset($this->data[$offset]); }
15+
public function offsetGet($offset): mixed { return $this->data[$offset]; }
16+
public function offsetSet($offset, $data): void { $this->data[$offset] = $data; }
17+
public function offsetUnset($offset): void { unset($this->data[$offset]); }
18+
public function offsetExists($offset): bool { return isset($this->data[$offset]); }
1919
};
2020
}
2121
}

Zend/tests/anon/005.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class Outer {
1414
/* create a child object implementing array access */
1515
/* this grants you access to protected methods and members */
1616
return new class($this->data) implements ArrayAccess {
17-
public function offsetGet($offset) { return $this->data[$offset]; }
18-
public function offsetSet($offset, $data) { return ($this->data[$offset] = $data); }
19-
public function offsetUnset($offset) { unset($this->data[$offset]); }
20-
public function offsetExists($offset) { return isset($this->data[$offset]); }
17+
public function offsetGet($offset): mixed { return $this->data[$offset]; }
18+
public function offsetSet($offset, $data): void { $this->data[$offset] = $data; }
19+
public function offsetUnset($offset): void { unset($this->data[$offset]); }
20+
public function offsetExists($offset): bool { return isset($this->data[$offset]); }
2121
};
2222
}
2323
}

Zend/tests/arg_unpack/traversable_throwing_exception.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function test(...$args) {
88
}
99

1010
class Foo implements IteratorAggregate {
11-
public function getIterator() {
11+
public function getIterator(): Traversable {
1212
throw new Exception('getIterator');
1313
}
1414
}

Zend/tests/argument_restriction_005.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Bug #55719 (Argument restriction should come with a more specific error message)
33
--FILE--
44
<?php
55
class Sub implements ArrayAccess {
6-
public function offsetSet() {
6+
public function offsetSet(): void {
77
}
88
}
99
?>
1010
--EXPECTF--
11-
Fatal error: Declaration of Sub::offsetSet() must be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value) in %sargument_restriction_005.php on line %d
11+
Fatal error: Declaration of Sub::offsetSet(): void must be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void in %sargument_restriction_005.php on line %d

Zend/tests/assign_coalesce_002.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ try {
2626
var_dump($ary);
2727

2828
class AA implements ArrayAccess {
29-
public function offsetExists($k) {
29+
public function offsetExists($k): bool {
3030
return true;
3131
}
32-
public function &offsetGet($k) {
32+
public function &offsetGet($k): mixed {
3333
$var = ["foo" => "bar"];
3434
return $var;
3535
}
36-
public function offsetSet($k,$v) {}
37-
public function offsetUnset($k) {}
36+
public function offsetSet($k,$v): void {}
37+
public function offsetUnset($k): void {}
3838
}
3939

4040
class Dtor {
@@ -52,14 +52,14 @@ try {
5252
var_dump($foo);
5353

5454
class AA2 implements ArrayAccess {
55-
public function offsetExists($k) {
55+
public function offsetExists($k): bool {
5656
return false;
5757
}
58-
public function offsetGet($k) {
58+
public function offsetGet($k): mixed {
5959
return null;
6060
}
61-
public function offsetSet($k,$v) {}
62-
public function offsetUnset($k) {}
61+
public function offsetSet($k,$v): void {}
62+
public function offsetUnset($k): void {}
6363
}
6464

6565
$ary = ["foo" => new AA2];

Zend/tests/assign_coalesce_003.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ class AA implements ArrayAccess {
1313
public function __construct($data = []) {
1414
$this->data = $data;
1515
}
16-
public function &offsetGet($k) {
16+
public function &offsetGet($k): mixed {
1717
echo "offsetGet($k)\n";
1818
return $this->data[$k];
1919
}
20-
public function offsetExists($k) {
20+
public function offsetExists($k): bool {
2121
echo "offsetExists($k)\n";
2222
return array_key_exists($k, $this->data);
2323
}
24-
public function offsetSet($k,$v) {
24+
public function offsetSet($k,$v): void {
2525
echo "offsetSet($k,$v)\n";
2626
$this->data[$k] = $v;
2727
}
28-
public function offsetUnset($k) { }
28+
public function offsetUnset($k): void { }
2929
}
3030

3131
$ary = new AA(["foo" => new AA, "null" => null]);

Zend/tests/bug26229.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Bug #26229 (getIterator() segfaults when it returns arrays or scalars)
44
<?php
55

66
class array_iterator implements IteratorAggregate {
7+
#[ReturnTypeWillChange]
78
public function getIterator() {
89
return array('foo', 'bar');
910
}

Zend/tests/bug30346.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Bug #30346 (arrayAccess and using $this)
66
class Test implements ArrayAccess
77
{
88
public function __construct() { }
9-
public function offsetExists( $offset ) { return false; }
10-
public function offsetGet( $offset ) { return $offset; }
11-
public function offsetSet( $offset, $data ) { }
12-
public function offsetUnset( $offset ) { }
9+
public function offsetExists( $offset ): bool { return false; }
10+
public function offsetGet( $offset ): mixed { return $offset; }
11+
public function offsetSet( $offset, $data ): void { }
12+
public function offsetUnset( $offset ): void { }
1313
}
1414

1515
$post = new Test;

Zend/tests/bug30725.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bug #30725 (PHP segfaults when an exception is thrown in getIterator() within fo
55

66
class Test implements IteratorAggregate
77
{
8-
function getIterator()
8+
function getIterator(): Traversable
99
{
1010
throw new Exception();
1111
}

Zend/tests/bug31683.phpt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,26 @@ class Foo implements ArrayAccess {
2222
$test = 'bug';
2323
}
2424

25-
function offsetget($test) {
25+
function offsetget($test): mixed {
2626
var_dump($test);
2727
$test = 'bug';
2828
return 123;
2929
}
3030

31-
function offsetset($test, $val) {
31+
function offsetset($test, $val): void {
3232
var_dump($test);
3333
var_dump($val);
3434
$test = 'bug';
3535
$val = 'bug';
3636
}
3737

38-
function offsetexists($test) {
38+
function offsetexists($test): bool {
3939
var_dump($test);
4040
$test = 'bug';
41+
return true;
4142
}
4243

43-
function offsetunset($test) {
44+
function offsetunset($test): void {
4445
var_dump($test);
4546
$test = 'bug';
4647
}

Zend/tests/bug32252.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ Bug #32252 (Segfault when offsetSet throws an Exception (only without debug))
55

66
class Test implements ArrayAccess
77
{
8-
function offsetExists($offset)
8+
function offsetExists($offset): bool
99
{
1010
echo __METHOD__ . "($offset)\n";
1111
return false;
1212
}
1313

14-
function offsetGet($offset)
14+
function offsetGet($offset): mixed
1515
{
1616
echo __METHOD__ . "($offset)\n";
1717
return null;
1818
}
1919

20-
function offsetSet($offset, $value)
20+
function offsetSet($offset, $value): void
2121
{
2222
echo __METHOD__ . "($offset, $value)\n";
2323
throw new Exception("Ooops");
2424
}
2525

26-
function offsetUnset($offset)
26+
function offsetUnset($offset): void
2727
{
2828
echo __METHOD__ . "($offset)\n";
2929
}

Zend/tests/bug32674.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ class collection implements Iterator {
99
public function __construct() {
1010
}
1111

12-
public function rewind() {
12+
public function rewind(): void {
1313
reset($this->_elements);
1414
}
1515

16-
public function count() {
16+
public function count(): int {
1717
return count($this->_elements);
1818
}
1919

20-
public function current() {
20+
public function current(): mixed {
2121
$element = current($this->_elements);
2222
return $element;
2323
}
2424

25-
public function next() {
25+
public function next(): void {
2626
$element = next($this->_elements);
27-
return $element;
27+
$element;
2828
}
2929

30-
public function key() {
30+
public function key(): mixed {
3131
$this->_fillCollection();
3232
$element = key($this->_elements);
3333
return $element;
3434
}
3535

36-
public function valid() {
36+
public function valid(): bool {
3737
throw new Exception('shit happened');
3838

3939
return ($this->current() !== false);

Zend/tests/bug32993.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ class Test implements Iterator {
66

77
public $arr = array();
88

9-
public function rewind() { return reset($this->arr); }
10-
public function current() { throw new Exception(); }
9+
public function rewind(): void { reset($this->arr); }
10+
public function current(): mixed { throw new Exception(); }
1111
public function key() { return key($this->arr); }
12-
public function next() { return next($this->arr); }
13-
public function valid() { return (current($this->arr) !== false); }
12+
public function next(): void { next($this->arr); }
13+
public function valid(): bool { return (current($this->arr) !== false); }
1414
}
1515

1616
$t = new Test();

Zend/tests/bug33710.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Bug #33710 (ArrayAccess objects doesn't initialize $this)
55

66
class Foo implements ArrayAccess
77
{
8-
function offsetExists($offset) {/*...*/}
9-
function offsetGet($offset) {/*...*/}
10-
function offsetSet($offset, $value) {/*...*/}
11-
function offsetUnset($offset) {/*...*/}
8+
function offsetExists($offset): bool { return true;}
9+
function offsetGet($offset): mixed { return null; }
10+
function offsetSet($offset, $value): void {/*...*/}
11+
function offsetUnset($offset): void {/*...*/}
1212

1313
function fail()
1414
{

Zend/tests/bug39297.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ class MyTree implements ArrayAccess {
1010
public $parent;
1111
public $children = array();
1212

13-
public function offsetExists($offset) {
13+
public function offsetExists($offset): bool {
1414
}
1515

16-
public function offsetUnset($offset) {
16+
public function offsetUnset($offset): void {
1717
}
1818

19-
public function offsetSet($offset, $value) {
19+
public function offsetSet($offset, $value): void {
2020
echo "offsetSet()\n";
2121
$cannonicalName = strtolower($offset);
2222
$this->children[$cannonicalName] = $value;
2323
$value->parent = $this;
2424
}
2525

26-
public function offsetGet($offset) {
26+
public function offsetGet($offset): mixed {
2727
echo "offsetGet()\n";
2828
$cannonicalName = strtolower($offset);
2929
return $this->children[$cannonicalName];

Zend/tests/bug40833.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ Bug #40833 (Crash when using unset() on an ArrayAccess object retrieved via __ge
3535
$this->entity->whatever = null;
3636
}
3737

38-
function offsetUnset($offset)
38+
function offsetUnset($offset): void
3939
{
4040
$this->clear();
4141
// $this->entity->{$this->name} = null;
4242
}
4343

44-
function offsetSet($offset, $value)
44+
function offsetSet($offset, $value): void
4545
{
4646
}
4747

48-
function offsetGet($offset)
48+
function offsetGet($offset): mixed
4949
{
5050
return 'Bogus ';
5151
}
5252

53-
function offsetExists($offset)
53+
function offsetExists($offset): bool
5454
{
5555
}
5656
}

Zend/tests/bug41209.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class cache implements ArrayAccess
2020
{
2121
private $container = array();
2222

23-
public function offsetGet($id) {}
23+
public function offsetGet($id): mixed {}
2424

25-
public function offsetSet($id, $value) {}
25+
public function offsetSet($id, $value): void {}
2626

27-
public function offsetUnset($id) {}
27+
public function offsetUnset($id): void {}
2828

29-
public function offsetExists($id)
29+
public function offsetExists($id): bool
3030
{
3131
return isset($this->containers[(string) $id]);
3232
}

Zend/tests/bug49269.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Bug #49269 (Ternary operator fails on Iterator object when used inside foreach d
55
class TestObject implements Iterator
66
{
77
public $n = 0;
8-
function valid()
8+
function valid(): bool
99
{
1010
return ($this->n < 3);
1111
}
12-
function current() {return $this->n;}
13-
function next() {$this->n++;}
14-
function key() { }
15-
function rewind() {$this->n = 0;}
12+
function current(): mixed {return $this->n;}
13+
function next(): void {$this->n++;}
14+
function key(): mixed { }
15+
function rewind(): void {$this->n = 0;}
1616
}
1717

1818

0 commit comments

Comments
 (0)