Skip to content

Commit 787db3a

Browse files
authored
Declare tentative return types for ext/session (#7005)
1 parent 100a1e8 commit 787db3a

32 files changed

+201
-191
lines changed

ext/session/session.stub.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,60 +65,60 @@ function session_start(array $options = []): bool {}
6565

6666
interface SessionHandlerInterface
6767
{
68-
/** @return bool */
69-
public function open(string $path, string $name);
68+
/** @tentative-return-type */
69+
public function open(string $path, string $name): bool;
7070

71-
/** @return bool */
72-
public function close();
71+
/** @tentative-return-type */
72+
public function close(): bool;
7373

74-
/** @return string|false */
75-
public function read(string $id);
74+
/** @tentative-return-type */
75+
public function read(string $id): string|false;
7676

77-
/** @return bool */
78-
public function write(string $id, string $data);
77+
/** @tentative-return-type */
78+
public function write(string $id, string $data): bool;
7979

80-
/** @return bool */
81-
public function destroy(string $id);
80+
/** @tentative-return-type */
81+
public function destroy(string $id): bool;
8282

83-
/** @return int|false */
84-
public function gc(int $max_lifetime);
83+
/** @tentative-return-type */
84+
public function gc(int $max_lifetime): int|false;
8585
}
8686

8787
interface SessionIdInterface
8888
{
89-
/** @return string */
90-
public function create_sid();
89+
/** @tentative-return-type */
90+
public function create_sid(): string;
9191
}
9292

9393
interface SessionUpdateTimestampHandlerInterface
9494
{
95-
/** @return bool */
96-
public function validateId(string $id);
95+
/** @tentative-return-type */
96+
public function validateId(string $id): bool;
9797

98-
/** @return bool */
99-
public function updateTimestamp(string $id, string $data);
98+
/** @tentative-return-type */
99+
public function updateTimestamp(string $id, string $data): bool;
100100
}
101101

102102
class SessionHandler implements SessionHandlerInterface, SessionIdInterface
103103
{
104-
/** @return bool */
105-
public function open(string $path, string $name) {}
104+
/** @tentative-return-type */
105+
public function open(string $path, string $name): bool {}
106106

107-
/** @return bool */
108-
public function close() {}
107+
/** @tentative-return-type */
108+
public function close(): bool {}
109109

110-
/** @return string|false */
111-
public function read(string $id) {}
110+
/** @tentative-return-type */
111+
public function read(string $id): string|false {}
112112

113-
/** @return bool */
114-
public function write(string $id, string $data) {}
113+
/** @tentative-return-type */
114+
public function write(string $id, string $data): bool {}
115115

116-
/** @return bool */
117-
public function destroy(string $id) {}
116+
/** @tentative-return-type */
117+
public function destroy(string $id): bool {}
118118

119-
/** @return int|false */
120-
public function gc(int $max_lifetime) {}
119+
/** @tentative-return-type */
120+
public function gc(int $max_lifetime): int|false {}
121121

122-
/** @return string */
123-
public function create_sid() {}
122+
/** @tentative-return-type */
123+
public function create_sid(): string {}
124124
}

ext/session/session_arginfo.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: f7f6a3d0357da86516b42fcd5cc2e618aa0049b8 */
2+
* Stub hash: 6838259167ac6edd5a4f6adec9fddf838f301337 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_name, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null")
@@ -89,32 +89,35 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_session_start, 0, 0, _IS_BOOL, 0
8989
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]")
9090
ZEND_END_ARG_INFO()
9191

92-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_open, 0, 0, 2)
92+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionHandlerInterface_open, 0, 2, _IS_BOOL, 0)
9393
ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
9494
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
9595
ZEND_END_ARG_INFO()
9696

97-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_close, 0, 0, 0)
97+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionHandlerInterface_close, 0, 0, _IS_BOOL, 0)
9898
ZEND_END_ARG_INFO()
9999

100-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_read, 0, 0, 1)
100+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_SessionHandlerInterface_read, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
101101
ZEND_ARG_TYPE_INFO(0, id, IS_STRING, 0)
102102
ZEND_END_ARG_INFO()
103103

104-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_write, 0, 0, 2)
104+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionHandlerInterface_write, 0, 2, _IS_BOOL, 0)
105105
ZEND_ARG_TYPE_INFO(0, id, IS_STRING, 0)
106106
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
107107
ZEND_END_ARG_INFO()
108108

109-
#define arginfo_class_SessionHandlerInterface_destroy arginfo_class_SessionHandlerInterface_read
109+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionHandlerInterface_destroy, 0, 1, _IS_BOOL, 0)
110+
ZEND_ARG_TYPE_INFO(0, id, IS_STRING, 0)
111+
ZEND_END_ARG_INFO()
110112

111-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_gc, 0, 0, 1)
113+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_SessionHandlerInterface_gc, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
112114
ZEND_ARG_TYPE_INFO(0, max_lifetime, IS_LONG, 0)
113115
ZEND_END_ARG_INFO()
114116

115-
#define arginfo_class_SessionIdInterface_create_sid arginfo_class_SessionHandlerInterface_close
117+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionIdInterface_create_sid, 0, 0, IS_STRING, 0)
118+
ZEND_END_ARG_INFO()
116119

117-
#define arginfo_class_SessionUpdateTimestampHandlerInterface_validateId arginfo_class_SessionHandlerInterface_read
120+
#define arginfo_class_SessionUpdateTimestampHandlerInterface_validateId arginfo_class_SessionHandlerInterface_destroy
118121

119122
#define arginfo_class_SessionUpdateTimestampHandlerInterface_updateTimestamp arginfo_class_SessionHandlerInterface_write
120123

@@ -126,11 +129,11 @@ ZEND_END_ARG_INFO()
126129

127130
#define arginfo_class_SessionHandler_write arginfo_class_SessionHandlerInterface_write
128131

129-
#define arginfo_class_SessionHandler_destroy arginfo_class_SessionHandlerInterface_read
132+
#define arginfo_class_SessionHandler_destroy arginfo_class_SessionHandlerInterface_destroy
130133

131134
#define arginfo_class_SessionHandler_gc arginfo_class_SessionHandlerInterface_gc
132135

133-
#define arginfo_class_SessionHandler_create_sid arginfo_class_SessionHandlerInterface_close
136+
#define arginfo_class_SessionHandler_create_sid arginfo_class_SessionIdInterface_create_sid
134137

135138

136139
ZEND_FUNCTION(session_name);

ext/session/tests/004.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ ob_start();
1515

1616
class handler {
1717
public $data = 'baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}';
18-
function open($save_path, $session_name)
18+
function open($save_path, $session_name): bool
1919
{
2020
print "OPEN: $session_name\n";
2121
return true;
2222
}
23-
function close()
23+
function close(): bool
2424
{
2525
return true;
2626
}
27-
function read($key)
27+
function read($key): string|false
2828
{
2929
print "READ: $key\n";
3030
return $GLOBALS["hnd"]->data;
3131
}
3232

33-
function write($key, $val)
33+
function write($key, $val): bool
3434
{
3535
print "WRITE: $key, $val\n";
3636
$GLOBALS["hnd"]->data = $val;
3737
return true;
3838
}
3939

40-
function destroy($key)
40+
function destroy($key): bool
4141
{
4242
print "DESTROY: $key\n";
4343
return true;

ext/session/tests/005.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ ob_start();
1515

1616
class handler {
1717
public $data = 'baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}';
18-
function open($save_path, $session_name)
18+
function open($save_path, $session_name): bool
1919
{
2020
print "OPEN: $session_name\n";
2121
return true;
2222
}
23-
function close()
23+
function close(): bool
2424
{
2525
print "CLOSE\n";
2626
return true;
2727
}
28-
function read($key)
28+
function read($key): string|false
2929
{
3030
print "READ: $key\n";
3131
return $GLOBALS["hnd"]->data;
3232
}
3333

34-
function write($key, $val)
34+
function write($key, $val): bool
3535
{
3636
print "WRITE: $key, $val\n";
3737
$GLOBALS["hnd"]->data = $val;
3838
return true;
3939
}
4040

41-
function destroy($key)
41+
function destroy($key): bool
4242
{
4343
print "DESTROY: $key\n";
4444
return true;

ext/session/tests/024.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ ob_start();
1616
class handler {
1717
public $data = 'baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}';
1818

19-
function open($save_path, $session_name)
19+
function open($save_path, $session_name): bool
2020
{
2121
print "OPEN: $session_name\n";
2222
return true;
2323
}
24-
function close()
24+
function close(): bool
2525
{
2626
return true;
2727
}
28-
function read($key)
28+
function read($key): string|false
2929
{
3030
print "READ: $key\n";
3131
return $GLOBALS["hnd"]->data;
3232
}
3333

34-
function write($key, $val)
34+
function write($key, $val): bool
3535
{
3636
print "WRITE: $key, $val\n";
3737
$GLOBALS["hnd"]->data = $val;
3838
return true;
3939
}
4040

41-
function destroy($key)
41+
function destroy($key): bool
4242
{
4343
print "DESTROY: $key\n";
4444
return true;

ext/session/tests/025.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@ ob_start();
1616
class handler {
1717
public $data = 'baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}';
1818

19-
function open($save_path, $session_name)
19+
function open($save_path, $session_name): bool
2020
{
2121
print "OPEN: $session_name\n";
2222
return true;
2323
}
24-
function close()
24+
function close(): bool
2525
{
2626
print "CLOSE\n";
2727
return true;
2828
}
29-
function read($key)
29+
function read($key): string|false
3030
{
3131
print "READ: $key\n";
3232
return $GLOBALS["hnd"]->data;
3333
}
3434

35-
function write($key, $val)
35+
function write($key, $val): bool
3636
{
3737
print "WRITE: $key, $val\n";
3838
$GLOBALS["hnd"]->data = $val;
3939
return true;
4040
}
4141

42-
function destroy($key)
42+
function destroy($key): bool
4343
{
4444
print "DESTROY: $key\n";
4545
return true;

ext/session/tests/bug60634_error_3.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function write($id, $session_data) {
2929
undefined_function();
3030
}
3131

32-
function destroy($id) {
32+
function destroy($id): bool {
3333
return true;
3434
}
3535

ext/session/tests/bug70133.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ session.use_strict_mode=0
1111

1212
class CustomReadHandler extends \SessionHandler {
1313

14-
public function read($session_id) {
14+
public function read($session_id): string|false {
1515
return parent::read('mycustomsession');
1616
}
1717
}

ext/session/tests/bug71162.phpt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,40 @@ Current session module is designed to write empty session always. In addition, c
1111
<?php
1212
class MySessionHandler extends SessionHandler implements SessionUpdateTimestampHandlerInterface
1313
{
14-
public function open($path, $sessname) {
14+
public function open($path, $sessname): bool {
1515
return TRUE;
1616
}
1717

18-
public function close() {
18+
public function close(): bool {
1919
return TRUE;
2020
}
2121

22-
public function read($sessid) {
22+
public function read($sessid): string|false {
2323
return '';
2424
}
2525

26-
public function write($sessid, $sessdata) {
26+
public function write($sessid, $sessdata): bool {
2727
echo __FUNCTION__, PHP_EOL;
2828
return TRUE;
2929
}
3030

31-
public function destroy($sessid) {
31+
public function destroy($sessid): bool {
3232
return TRUE;
3333
}
3434

35-
public function gc($maxlifetime) {
35+
public function gc($maxlifetime): int|false {
3636
return TRUE;
3737
}
3838

39-
public function create_sid() {
39+
public function create_sid(): string {
4040
return sha1(random_bytes(32));
4141
}
4242

43-
public function validateId($sid) {
43+
public function validateId($sid): bool {
4444
return TRUE;
4545
}
4646

47-
public function updateTimestamp($sessid, $sessdata) {
47+
public function updateTimestamp($sessid, $sessdata): bool {
4848
echo __FUNCTION__, PHP_EOL;
4949
return TRUE;
5050
}

0 commit comments

Comments
 (0)