Skip to content

Commit 6d805ed

Browse files
committed
Declare tentative return types for ext/spl - part 2
Closes GH-7235
1 parent 02b803a commit 6d805ed

30 files changed

+403
-366
lines changed

Zend/tests/ns_054.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
namespace test\ns1;
66

77
class Foo implements \SplObserver {
8-
function update(\SplSubject $x) {
8+
function update(\SplSubject $x): void {
99
echo "ok\n";
1010
}
1111
}
1212

1313
class Bar implements \SplSubject {
14-
function attach(\SplObserver $x) {
14+
function attach(\SplObserver $x): void {
1515
echo "ok\n";
1616
}
17-
function notify() {
17+
function notify(): void {
1818
}
19-
function detach(\SplObserver $x) {
19+
function detach(\SplObserver $x): void {
2020
}
2121
}
2222
$foo = new Foo();

Zend/tests/ns_056.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ namespace test\ns1;
66
use \SplObserver;
77

88
class Foo implements SplObserver {
9-
function update(\SplSubject $x) {
9+
function update(\SplSubject $x): void {
1010
echo "ok\n";
1111
}
1212
}
1313

1414
class Bar implements \SplSubject {
15-
function attach(SplObserver $x) {
15+
function attach(SplObserver $x): void {
1616
echo "ok\n";
1717
}
18-
function notify() {
18+
function notify(): void {
1919
}
20-
function detach(SplObserver $x) {
20+
function detach(SplObserver $x): void {
2121
}
2222
}
2323
$foo = new Foo();

ext/spl/spl_dllist.stub.php

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,110 +4,110 @@
44

55
class SplDoublyLinkedList implements Iterator, Countable, ArrayAccess, Serializable
66
{
7-
/** @return void */
8-
public function add(int $index, mixed $value) {}
7+
/** @tentative-return-type */
8+
public function add(int $index, mixed $value): void {}
99

10-
/** @return mixed */
11-
public function pop() {}
10+
/** @tentative-return-type */
11+
public function pop(): mixed {}
1212

13-
/** @return mixed */
14-
public function shift() {}
13+
/** @tentative-return-type */
14+
public function shift(): mixed {}
1515

16-
/** @return void */
17-
public function push(mixed $value) {}
16+
/** @tentative-return-type */
17+
public function push(mixed $value): void {}
1818

19-
/** @return void */
20-
public function unshift(mixed $value) {}
19+
/** @tentative-return-type */
20+
public function unshift(mixed $value): void {}
2121

22-
/** @return mixed */
23-
public function top() {}
22+
/** @tentative-return-type */
23+
public function top(): mixed {}
2424

25-
/** @return mixed */
26-
public function bottom() {}
25+
/** @tentative-return-type */
26+
public function bottom(): mixed {}
2727

28-
/** @return array */
29-
public function __debugInfo() {}
28+
/** @tentative-return-type */
29+
public function __debugInfo(): array {}
3030

31-
/** @return int */
32-
public function count() {}
31+
/** @tentative-return-type */
32+
public function count(): int {}
3333

34-
/** @return bool */
35-
public function isEmpty() {}
34+
/** @tentative-return-type */
35+
public function isEmpty(): bool {}
3636

37-
/** @return int */
38-
public function setIteratorMode(int $mode) {}
37+
/** @tentative-return-type */
38+
public function setIteratorMode(int $mode): int {}
3939

40-
/** @return int */
41-
public function getIteratorMode() {}
40+
/** @tentative-return-type */
41+
public function getIteratorMode(): int {}
4242

4343
/**
4444
* @param int $index
45-
* @return bool
45+
* @tentative-return-type
4646
*/
47-
public function offsetExists($index) {}
47+
public function offsetExists($index): bool {}
4848

4949
/**
5050
* @param int $index
51-
* @return mixed
51+
* @tentative-return-type
5252
*/
53-
public function offsetGet($index) {}
53+
public function offsetGet($index): mixed {}
5454

5555
/**
5656
* @param int|null $index
57-
* @return void
57+
* @tentative-return-type
5858
*/
59-
public function offsetSet($index, mixed $value) {}
59+
public function offsetSet($index, mixed $value): void {}
6060

6161
/**
6262
* @param int $index
63-
* @return void
63+
* @tentative-return-type
6464
*/
65-
public function offsetUnset($index) {}
65+
public function offsetUnset($index): void {}
6666

67-
/** @return void */
68-
public function rewind() {}
67+
/** @tentative-return-type */
68+
public function rewind(): void {}
6969

70-
/** @return mixed */
71-
public function current() {}
70+
/** @tentative-return-type */
71+
public function current(): mixed {}
7272

73-
/** @return int */
74-
public function key() {}
73+
/** @tentative-return-type */
74+
public function key(): int {}
7575

76-
/** @return void */
77-
public function prev() {}
76+
/** @tentative-return-type */
77+
public function prev(): void {}
7878

79-
/** @return void */
80-
public function next() {}
79+
/** @tentative-return-type */
80+
public function next(): void {}
8181

82-
/** @return bool */
83-
public function valid() {}
82+
/** @tentative-return-type */
83+
public function valid(): bool {}
8484

85-
/** @return void */
86-
public function unserialize(string $data) {}
85+
/** @tentative-return-type */
86+
public function unserialize(string $data): void {}
8787

88-
/** @return string */
89-
public function serialize() {}
88+
/** @tentative-return-type */
89+
public function serialize(): string {}
9090

91-
/** @return array */
92-
public function __serialize() {}
91+
/** @tentative-return-type */
92+
public function __serialize(): array {}
9393

94-
/** @return void */
95-
public function __unserialize(array $data) {}
94+
/** @tentative-return-type */
95+
public function __unserialize(array $data): void {}
9696
}
9797

9898
class SplQueue extends SplDoublyLinkedList
9999
{
100100
/**
101-
* @return void
101+
* @tentative-return-type
102102
* @implementation-alias SplDoublyLinkedList::push
103103
*/
104-
public function enqueue(mixed $value) {}
104+
public function enqueue(mixed $value): void {}
105105

106106
/**
107-
* @return mixed
107+
* @tentative-return-type
108108
* @implementation-alias SplDoublyLinkedList::shift
109109
*/
110-
public function dequeue() {}
110+
public function dequeue(): mixed {}
111111
}
112112

113113
class SplStack extends SplDoublyLinkedList

ext/spl/spl_dllist_arginfo.h

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: d0c98e1628895a81ac0b4abe62dede9ed2c7f55e */
2+
* Stub hash: 4631669bb268bb2c9e005fa7ee385245604c1d71 */
33

4-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplDoublyLinkedList_add, 0, 0, 2)
4+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_add, 0, 2, IS_VOID, 0)
55
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
66
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
77
ZEND_END_ARG_INFO()
88

9-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplDoublyLinkedList_pop, 0, 0, 0)
9+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_pop, 0, 0, IS_MIXED, 0)
1010
ZEND_END_ARG_INFO()
1111

1212
#define arginfo_class_SplDoublyLinkedList_shift arginfo_class_SplDoublyLinkedList_pop
1313

14-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplDoublyLinkedList_push, 0, 0, 1)
14+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_push, 0, 1, IS_VOID, 0)
1515
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
1616
ZEND_END_ARG_INFO()
1717

@@ -21,52 +21,61 @@ ZEND_END_ARG_INFO()
2121

2222
#define arginfo_class_SplDoublyLinkedList_bottom arginfo_class_SplDoublyLinkedList_pop
2323

24-
#define arginfo_class_SplDoublyLinkedList___debugInfo arginfo_class_SplDoublyLinkedList_pop
24+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList___debugInfo, 0, 0, IS_ARRAY, 0)
25+
ZEND_END_ARG_INFO()
2526

26-
#define arginfo_class_SplDoublyLinkedList_count arginfo_class_SplDoublyLinkedList_pop
27+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_count, 0, 0, IS_LONG, 0)
28+
ZEND_END_ARG_INFO()
2729

28-
#define arginfo_class_SplDoublyLinkedList_isEmpty arginfo_class_SplDoublyLinkedList_pop
30+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_isEmpty, 0, 0, _IS_BOOL, 0)
31+
ZEND_END_ARG_INFO()
2932

30-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplDoublyLinkedList_setIteratorMode, 0, 0, 1)
33+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_setIteratorMode, 0, 1, IS_LONG, 0)
3134
ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
3235
ZEND_END_ARG_INFO()
3336

34-
#define arginfo_class_SplDoublyLinkedList_getIteratorMode arginfo_class_SplDoublyLinkedList_pop
37+
#define arginfo_class_SplDoublyLinkedList_getIteratorMode arginfo_class_SplDoublyLinkedList_count
3538

36-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplDoublyLinkedList_offsetExists, 0, 0, 1)
39+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_offsetExists, 0, 1, _IS_BOOL, 0)
3740
ZEND_ARG_INFO(0, index)
3841
ZEND_END_ARG_INFO()
3942

40-
#define arginfo_class_SplDoublyLinkedList_offsetGet arginfo_class_SplDoublyLinkedList_offsetExists
43+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_offsetGet, 0, 1, IS_MIXED, 0)
44+
ZEND_ARG_INFO(0, index)
45+
ZEND_END_ARG_INFO()
4146

42-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplDoublyLinkedList_offsetSet, 0, 0, 2)
47+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_offsetSet, 0, 2, IS_VOID, 0)
4348
ZEND_ARG_INFO(0, index)
4449
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
4550
ZEND_END_ARG_INFO()
4651

47-
#define arginfo_class_SplDoublyLinkedList_offsetUnset arginfo_class_SplDoublyLinkedList_offsetExists
52+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_offsetUnset, 0, 1, IS_VOID, 0)
53+
ZEND_ARG_INFO(0, index)
54+
ZEND_END_ARG_INFO()
4855

49-
#define arginfo_class_SplDoublyLinkedList_rewind arginfo_class_SplDoublyLinkedList_pop
56+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_rewind, 0, 0, IS_VOID, 0)
57+
ZEND_END_ARG_INFO()
5058

5159
#define arginfo_class_SplDoublyLinkedList_current arginfo_class_SplDoublyLinkedList_pop
5260

53-
#define arginfo_class_SplDoublyLinkedList_key arginfo_class_SplDoublyLinkedList_pop
61+
#define arginfo_class_SplDoublyLinkedList_key arginfo_class_SplDoublyLinkedList_count
5462

55-
#define arginfo_class_SplDoublyLinkedList_prev arginfo_class_SplDoublyLinkedList_pop
63+
#define arginfo_class_SplDoublyLinkedList_prev arginfo_class_SplDoublyLinkedList_rewind
5664

57-
#define arginfo_class_SplDoublyLinkedList_next arginfo_class_SplDoublyLinkedList_pop
65+
#define arginfo_class_SplDoublyLinkedList_next arginfo_class_SplDoublyLinkedList_rewind
5866

59-
#define arginfo_class_SplDoublyLinkedList_valid arginfo_class_SplDoublyLinkedList_pop
67+
#define arginfo_class_SplDoublyLinkedList_valid arginfo_class_SplDoublyLinkedList_isEmpty
6068

61-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplDoublyLinkedList_unserialize, 0, 0, 1)
69+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_unserialize, 0, 1, IS_VOID, 0)
6270
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
6371
ZEND_END_ARG_INFO()
6472

65-
#define arginfo_class_SplDoublyLinkedList_serialize arginfo_class_SplDoublyLinkedList_pop
73+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList_serialize, 0, 0, IS_STRING, 0)
74+
ZEND_END_ARG_INFO()
6675

67-
#define arginfo_class_SplDoublyLinkedList___serialize arginfo_class_SplDoublyLinkedList_pop
76+
#define arginfo_class_SplDoublyLinkedList___serialize arginfo_class_SplDoublyLinkedList___debugInfo
6877

69-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplDoublyLinkedList___unserialize, 0, 0, 1)
78+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SplDoublyLinkedList___unserialize, 0, 1, IS_VOID, 0)
7079
ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
7180
ZEND_END_ARG_INFO()
7281

ext/spl/spl_fixedarray.stub.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,47 @@ class SplFixedArray implements IteratorAggregate, ArrayAccess, Countable, JsonSe
66
{
77
public function __construct(int $size = 0) {}
88

9-
/** @return void */
10-
public function __wakeup() {}
9+
/** @tentative-return-type */
10+
public function __wakeup(): void {}
1111

12-
/** @return int */
13-
public function count() {}
12+
/** @tentative-return-type */
13+
public function count(): int {}
1414

15-
/** @return array */
16-
public function toArray() {}
15+
/** @tentative-return-type */
16+
public function toArray(): array {}
1717

18-
/** @return SplFixedArray */
19-
public static function fromArray(array $array, bool $preserveKeys = true) {}
18+
/** @tentative-return-type */
19+
public static function fromArray(array $array, bool $preserveKeys = true): SplFixedArray {}
2020

21-
/** @return int */
22-
public function getSize() {}
21+
/** @tentative-return-type */
22+
public function getSize(): int {}
2323

2424
/** @return bool */
25-
public function setSize(int $size) {}
25+
public function setSize(int $size) {} // TODO make return type void
2626

2727
/**
2828
* @param int $index
29-
* @return bool
29+
* @tentative-return-type
3030
*/
31-
public function offsetExists($index) {}
31+
public function offsetExists($index): bool {}
3232

3333
/**
3434
* @param int $index
35-
* @return mixed
35+
* @tentative-return-type
3636
*/
37-
public function offsetGet($index) {}
37+
public function offsetGet($index): mixed {}
3838

3939
/**
4040
* @param int $index
41-
* @return void
41+
* @tentative-return-type
4242
*/
43-
public function offsetSet($index, mixed $value) {}
43+
public function offsetSet($index, mixed $value): void {}
4444

4545
/**
4646
* @param int $index
47-
* @return void
47+
* @tentative-return-type
4848
*/
49-
public function offsetUnset($index) {}
49+
public function offsetUnset($index): void {}
5050

5151
public function getIterator(): Iterator {}
5252

0 commit comments

Comments
 (0)