From 597c8e6cecd5ecdc921936f3eafb9f34a5b48dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Thu, 27 May 2021 23:38:31 +0200 Subject: [PATCH] Declare tentative return types for ext/session --- ext/session/session.stub.php | 64 +++++++++---------- ext/session/session_arginfo.h | 25 ++++---- ext/session/tests/004.phpt | 10 +-- ext/session/tests/005.phpt | 10 +-- ext/session/tests/024.phpt | 10 +-- ext/session/tests/025.phpt | 10 +-- ext/session/tests/bug60634_error_3.phpt | 2 +- ext/session/tests/bug70133.phpt | 2 +- ext/session/tests/bug71162.phpt | 18 +++--- ext/session/tests/bug78624.phpt | 12 ++-- ext/session/tests/bug79091.phpt | 18 +++--- ext/session/tests/bug80889.phpt | 12 ++-- .../session_set_save_handler_class_001.phpt | 17 ++--- .../session_set_save_handler_class_002.phpt | 12 ++-- .../session_set_save_handler_class_003.phpt | 6 +- .../session_set_save_handler_class_005.phpt | 4 +- .../session_set_save_handler_class_006.phpt | 2 +- .../session_set_save_handler_class_007.phpt | 4 +- .../session_set_save_handler_class_008.phpt | 4 +- .../session_set_save_handler_class_009.phpt | 4 +- .../session_set_save_handler_class_010.phpt | 4 +- .../session_set_save_handler_class_011.phpt | 4 +- .../session_set_save_handler_class_012.phpt | 4 +- .../session_set_save_handler_class_013.phpt | 6 +- .../session_set_save_handler_class_016.phpt | 14 ++-- .../session_set_save_handler_class_017.phpt | 14 ++-- .../session_set_save_handler_class_018.phpt | 16 ++--- .../session_set_save_handler_iface_001.phpt | 12 ++-- .../session_set_save_handler_iface_002.phpt | 27 ++++---- .../session_set_save_handler_iface_003.phpt | 15 +++-- .../session_set_save_handler_sid_001.phpt | 14 ++-- .../session_set_save_handler_sid_002.phpt | 16 +++-- 32 files changed, 201 insertions(+), 191 deletions(-) diff --git a/ext/session/session.stub.php b/ext/session/session.stub.php index f171379b307b9..e5efdcdf070be 100644 --- a/ext/session/session.stub.php +++ b/ext/session/session.stub.php @@ -65,60 +65,60 @@ function session_start(array $options = []): bool {} interface SessionHandlerInterface { - /** @return bool */ - public function open(string $path, string $name); + /** @tentative-return-type */ + public function open(string $path, string $name): bool; - /** @return bool */ - public function close(); + /** @tentative-return-type */ + public function close(): bool; - /** @return string|false */ - public function read(string $id); + /** @tentative-return-type */ + public function read(string $id): string|false; - /** @return bool */ - public function write(string $id, string $data); + /** @tentative-return-type */ + public function write(string $id, string $data): bool; - /** @return bool */ - public function destroy(string $id); + /** @tentative-return-type */ + public function destroy(string $id): bool; - /** @return int|false */ - public function gc(int $max_lifetime); + /** @tentative-return-type */ + public function gc(int $max_lifetime): int|false; } interface SessionIdInterface { - /** @return string */ - public function create_sid(); + /** @tentative-return-type */ + public function create_sid(): string; } interface SessionUpdateTimestampHandlerInterface { - /** @return bool */ - public function validateId(string $id); + /** @tentative-return-type */ + public function validateId(string $id): bool; - /** @return bool */ - public function updateTimestamp(string $id, string $data); + /** @tentative-return-type */ + public function updateTimestamp(string $id, string $data): bool; } class SessionHandler implements SessionHandlerInterface, SessionIdInterface { - /** @return bool */ - public function open(string $path, string $name) {} + /** @tentative-return-type */ + public function open(string $path, string $name): bool {} - /** @return bool */ - public function close() {} + /** @tentative-return-type */ + public function close(): bool {} - /** @return string|false */ - public function read(string $id) {} + /** @tentative-return-type */ + public function read(string $id): string|false {} - /** @return bool */ - public function write(string $id, string $data) {} + /** @tentative-return-type */ + public function write(string $id, string $data): bool {} - /** @return bool */ - public function destroy(string $id) {} + /** @tentative-return-type */ + public function destroy(string $id): bool {} - /** @return int|false */ - public function gc(int $max_lifetime) {} + /** @tentative-return-type */ + public function gc(int $max_lifetime): int|false {} - /** @return string */ - public function create_sid() {} + /** @tentative-return-type */ + public function create_sid(): string {} } diff --git a/ext/session/session_arginfo.h b/ext/session/session_arginfo.h index b930e34f31c8a..d37735870b3b6 100644 --- a/ext/session/session_arginfo.h +++ b/ext/session/session_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: f7f6a3d0357da86516b42fcd5cc2e618aa0049b8 */ + * Stub hash: 6838259167ac6edd5a4f6adec9fddf838f301337 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_session_name, 0, 0, MAY_BE_STRING|MAY_BE_FALSE) 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 ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_open, 0, 0, 2) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionHandlerInterface_open, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_close, 0, 0, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionHandlerInterface_close, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_read, 0, 0, 1) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_SessionHandlerInterface_read, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, id, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_write, 0, 0, 2) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionHandlerInterface_write, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, id, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_END_ARG_INFO() -#define arginfo_class_SessionHandlerInterface_destroy arginfo_class_SessionHandlerInterface_read +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionHandlerInterface_destroy, 0, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, id, IS_STRING, 0) +ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SessionHandlerInterface_gc, 0, 0, 1) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_SessionHandlerInterface_gc, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, max_lifetime, IS_LONG, 0) ZEND_END_ARG_INFO() -#define arginfo_class_SessionIdInterface_create_sid arginfo_class_SessionHandlerInterface_close +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SessionIdInterface_create_sid, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO() -#define arginfo_class_SessionUpdateTimestampHandlerInterface_validateId arginfo_class_SessionHandlerInterface_read +#define arginfo_class_SessionUpdateTimestampHandlerInterface_validateId arginfo_class_SessionHandlerInterface_destroy #define arginfo_class_SessionUpdateTimestampHandlerInterface_updateTimestamp arginfo_class_SessionHandlerInterface_write @@ -126,11 +129,11 @@ ZEND_END_ARG_INFO() #define arginfo_class_SessionHandler_write arginfo_class_SessionHandlerInterface_write -#define arginfo_class_SessionHandler_destroy arginfo_class_SessionHandlerInterface_read +#define arginfo_class_SessionHandler_destroy arginfo_class_SessionHandlerInterface_destroy #define arginfo_class_SessionHandler_gc arginfo_class_SessionHandlerInterface_gc -#define arginfo_class_SessionHandler_create_sid arginfo_class_SessionHandlerInterface_close +#define arginfo_class_SessionHandler_create_sid arginfo_class_SessionIdInterface_create_sid ZEND_FUNCTION(session_name); diff --git a/ext/session/tests/004.phpt b/ext/session/tests/004.phpt index c3ed0c56165c5..b1f370eee44df 100644 --- a/ext/session/tests/004.phpt +++ b/ext/session/tests/004.phpt @@ -15,29 +15,29 @@ ob_start(); class handler { 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;}}'; - function open($save_path, $session_name) + function open($save_path, $session_name): bool { print "OPEN: $session_name\n"; return true; } - function close() + function close(): bool { return true; } - function read($key) + function read($key): string|false { print "READ: $key\n"; return $GLOBALS["hnd"]->data; } - function write($key, $val) + function write($key, $val): bool { print "WRITE: $key, $val\n"; $GLOBALS["hnd"]->data = $val; return true; } - function destroy($key) + function destroy($key): bool { print "DESTROY: $key\n"; return true; diff --git a/ext/session/tests/005.phpt b/ext/session/tests/005.phpt index 2b51ceed94841..e9dbf05cb71c5 100644 --- a/ext/session/tests/005.phpt +++ b/ext/session/tests/005.phpt @@ -15,30 +15,30 @@ ob_start(); class handler { 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;}}'; - function open($save_path, $session_name) + function open($save_path, $session_name): bool { print "OPEN: $session_name\n"; return true; } - function close() + function close(): bool { print "CLOSE\n"; return true; } - function read($key) + function read($key): string|false { print "READ: $key\n"; return $GLOBALS["hnd"]->data; } - function write($key, $val) + function write($key, $val): bool { print "WRITE: $key, $val\n"; $GLOBALS["hnd"]->data = $val; return true; } - function destroy($key) + function destroy($key): bool { print "DESTROY: $key\n"; return true; diff --git a/ext/session/tests/024.phpt b/ext/session/tests/024.phpt index 913956f5b37b6..75fa895d6b009 100644 --- a/ext/session/tests/024.phpt +++ b/ext/session/tests/024.phpt @@ -16,29 +16,29 @@ ob_start(); class handler { 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;}}'; - function open($save_path, $session_name) + function open($save_path, $session_name): bool { print "OPEN: $session_name\n"; return true; } - function close() + function close(): bool { return true; } - function read($key) + function read($key): string|false { print "READ: $key\n"; return $GLOBALS["hnd"]->data; } - function write($key, $val) + function write($key, $val): bool { print "WRITE: $key, $val\n"; $GLOBALS["hnd"]->data = $val; return true; } - function destroy($key) + function destroy($key): bool { print "DESTROY: $key\n"; return true; diff --git a/ext/session/tests/025.phpt b/ext/session/tests/025.phpt index 4e91da97960b9..e347a3ebdb316 100644 --- a/ext/session/tests/025.phpt +++ b/ext/session/tests/025.phpt @@ -16,30 +16,30 @@ ob_start(); class handler { 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;}}'; - function open($save_path, $session_name) + function open($save_path, $session_name): bool { print "OPEN: $session_name\n"; return true; } - function close() + function close(): bool { print "CLOSE\n"; return true; } - function read($key) + function read($key): string|false { print "READ: $key\n"; return $GLOBALS["hnd"]->data; } - function write($key, $val) + function write($key, $val): bool { print "WRITE: $key, $val\n"; $GLOBALS["hnd"]->data = $val; return true; } - function destroy($key) + function destroy($key): bool { print "DESTROY: $key\n"; return true; diff --git a/ext/session/tests/bug60634_error_3.phpt b/ext/session/tests/bug60634_error_3.phpt index 1909fc8ada451..5d6a35ac3d8d3 100644 --- a/ext/session/tests/bug60634_error_3.phpt +++ b/ext/session/tests/bug60634_error_3.phpt @@ -29,7 +29,7 @@ function write($id, $session_data) { undefined_function(); } -function destroy($id) { +function destroy($id): bool { return true; } diff --git a/ext/session/tests/bug70133.phpt b/ext/session/tests/bug70133.phpt index 3e019e483baf2..2a10e3121d366 100644 --- a/ext/session/tests/bug70133.phpt +++ b/ext/session/tests/bug70133.phpt @@ -11,7 +11,7 @@ session.use_strict_mode=0 class CustomReadHandler extends \SessionHandler { - public function read($session_id) { + public function read($session_id): string|false { return parent::read('mycustomsession'); } } diff --git a/ext/session/tests/bug71162.phpt b/ext/session/tests/bug71162.phpt index b475ae6080932..d16081c3145a4 100644 --- a/ext/session/tests/bug71162.phpt +++ b/ext/session/tests/bug71162.phpt @@ -11,40 +11,40 @@ Current session module is designed to write empty session always. In addition, c i; echo 'Open ', session_id(), "\n"; return parent::open($path, $name); } - public function create_sid() { + public function create_sid(): string { // This method should be removed when 5.5 become unsupported. ++$this->i; echo 'Old Create SID ', session_id(), "\n"; return parent::create_sid(); } - public function read($key) { + public function read($key): string|false { ++$this->i; echo 'Read ', session_id(), "\n"; return parent::read($key); } - public function write($key, $data) { + public function write($key, $data): bool { ++$this->i; echo 'Write ', session_id(), "\n"; return parent::write($key, $data); } - public function close() { + public function close(): bool { ++$this->i; echo 'Close ', session_id(), "\n"; return parent::close(); } - public function createSid() { + + public function createSid(): string { // User should use this rather than create_sid() // If both create_sid() and createSid() exists, // createSid() is used. @@ -49,7 +50,7 @@ class MySession extends SessionHandler { echo 'New Create ID ', session_id(), "\n"; return parent::create_sid(); } - public function validateId($key) { + public function validateId($key): bool { ++$this->i; echo 'Validate ID ', session_id(), "\n"; return TRUE; @@ -57,7 +58,7 @@ class MySession extends SessionHandler { // cannot call parent as follows. // return parent::validateSid($key); } - public function updateTimestamp($key, $data) { + public function updateTimestamp($key, $data): bool { ++$this->i; echo 'Update Timestamp ', session_id(), "\n"; return parent::write($key, $data); diff --git a/ext/session/tests/session_set_save_handler_class_002.phpt b/ext/session/tests/session_set_save_handler_class_002.phpt index 9a4a3a17936b9..72b1d02285345 100644 --- a/ext/session/tests/session_set_save_handler_class_002.phpt +++ b/ext/session/tests/session_set_save_handler_class_002.phpt @@ -15,7 +15,7 @@ echo "*** Testing session_set_save_handler() : full handler implementation ***\n class MySession2 extends SessionHandler { public $path; - public function open($path, $name) { + public function open($path, $name): bool { if (!$path) { $path = sys_get_temp_dir(); } @@ -23,24 +23,24 @@ class MySession2 extends SessionHandler { return true; } - public function close() { + public function close(): bool { return true; } - public function read($id) { + public function read($id): string|false { return (string)@file_get_contents($this->path . $id); } - public function write($id, $data) { + public function write($id, $data): bool { return (bool)file_put_contents($this->path . $id, $data); } - public function destroy($id) { + public function destroy($id): bool { @unlink($this->path . $id); return true; } - public function gc($maxlifetime) { + public function gc($maxlifetime): int|false { foreach (glob($this->path . '*') as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); diff --git a/ext/session/tests/session_set_save_handler_class_003.phpt b/ext/session/tests/session_set_save_handler_class_003.phpt index fe83c57d4cef8..b952a7ca9b7c9 100644 --- a/ext/session/tests/session_set_save_handler_class_003.phpt +++ b/ext/session/tests/session_set_save_handler_class_003.phpt @@ -14,18 +14,18 @@ echo "*** Testing session_set_save_handler() : inheritance ***\n"; class MySession3 extends SessionHandler { public $i = 0; - public function open($path, $name) { + public function open($path, $name): bool { ++$this->i; return parent::open($path, $name); } - public function read($key) { + public function read($key): string|false { ++$this->i; return parent::read($key); } } class MySession4 extends MySession3 { - public function write($id, $data) { + public function write($id, $data): bool { $this->i = "hai"; return parent::write($id, $data); } diff --git a/ext/session/tests/session_set_save_handler_class_005.phpt b/ext/session/tests/session_set_save_handler_class_005.phpt index cd2d831a01b26..00ff0df972001 100644 --- a/ext/session/tests/session_set_save_handler_class_005.phpt +++ b/ext/session/tests/session_set_save_handler_class_005.phpt @@ -14,12 +14,12 @@ ob_start(); echo "*** Testing session_set_save_handler() : incomplete implementation ***\n"; class MySession6 extends SessionHandler { - public function open($path, $name) { + public function open($path, $name): bool { // don't call parent return true; } - public function read($id) { + public function read($id): string|false { // should error because parent::open hasn't been called return parent::read($id); } diff --git a/ext/session/tests/session_set_save_handler_class_006.phpt b/ext/session/tests/session_set_save_handler_class_006.phpt index 161fb46d580a2..97b21e26e07e6 100644 --- a/ext/session/tests/session_set_save_handler_class_006.phpt +++ b/ext/session/tests/session_set_save_handler_class_006.phpt @@ -21,7 +21,7 @@ class MySession7_Foo { class MySession7 extends SessionHandler { public $foo; - public function close() { + public function close(): bool { var_dump($this->foo); @var_dump($GLOBALS['bar']); return parent::close(); diff --git a/ext/session/tests/session_set_save_handler_class_007.phpt b/ext/session/tests/session_set_save_handler_class_007.phpt index 5ace4fb9f13b6..d31e8750d2302 100644 --- a/ext/session/tests/session_set_save_handler_class_007.phpt +++ b/ext/session/tests/session_set_save_handler_class_007.phpt @@ -26,11 +26,11 @@ class MySession extends SessionHandler { echo "(#$this->num) finish called $id\n"; session_write_close(); } - public function write($id, $data) { + public function write($id, $data): bool { echo "(#$this->num) writing $id = $data\n"; return parent::write($id, $data); } - public function close() { + public function close(): bool { $id = session_id(); echo "(#$this->num) closing $id\n"; return parent::close(); diff --git a/ext/session/tests/session_set_save_handler_class_008.phpt b/ext/session/tests/session_set_save_handler_class_008.phpt index 227fe00961a9c..d9f81c4f524ff 100644 --- a/ext/session/tests/session_set_save_handler_class_008.phpt +++ b/ext/session/tests/session_set_save_handler_class_008.phpt @@ -26,11 +26,11 @@ class MySession extends SessionHandler { echo "(#$this->num) finish called $id\n"; session_write_close(); } - public function write($id, $data) { + public function write($id, $data): bool { echo "(#$this->num) writing $id = $data\n"; return parent::write($id, $data); } - public function close() { + public function close(): bool { $id = session_id(); echo "(#$this->num) closing $id\n"; return parent::close(); diff --git a/ext/session/tests/session_set_save_handler_class_009.phpt b/ext/session/tests/session_set_save_handler_class_009.phpt index 65e273d5e7288..c27b9b234789a 100644 --- a/ext/session/tests/session_set_save_handler_class_009.phpt +++ b/ext/session/tests/session_set_save_handler_class_009.phpt @@ -26,11 +26,11 @@ class MySession extends SessionHandler { echo "(#$this->num) finish called $id\n"; $this->shutdown(); } - public function write($id, $data) { + public function write($id, $data): bool { echo "(#$this->num) writing $id = $data\n"; return parent::write($id, $data); } - public function close() { + public function close(): bool { $id = session_id(); echo "(#$this->num) closing $id\n"; return parent::close(); diff --git a/ext/session/tests/session_set_save_handler_class_010.phpt b/ext/session/tests/session_set_save_handler_class_010.phpt index c81fce49635ee..39ae04b4952dc 100644 --- a/ext/session/tests/session_set_save_handler_class_010.phpt +++ b/ext/session/tests/session_set_save_handler_class_010.phpt @@ -26,11 +26,11 @@ class MySession extends SessionHandler { echo "(#$this->num) finish called $id\n"; session_write_close(); } - public function write($id, $data) { + public function write($id, $data): bool { echo "(#$this->num) writing $id = $data\n"; return parent::write($id, $data); } - public function close() { + public function close(): bool { $id = session_id(); echo "(#$this->num) closing $id\n"; return parent::close(); diff --git a/ext/session/tests/session_set_save_handler_class_011.phpt b/ext/session/tests/session_set_save_handler_class_011.phpt index 04defe937e491..a3811d2d9a152 100644 --- a/ext/session/tests/session_set_save_handler_class_011.phpt +++ b/ext/session/tests/session_set_save_handler_class_011.phpt @@ -23,7 +23,7 @@ class MySession extends SessionHandler { echo "(#$this->num) destructor called\n"; $this->destroyed = true; } - public function write($id, $data) { + public function write($id, $data): bool { if ($this->destroyed) { echo "(#$this->num) destroyed, cannot write\n"; } else { @@ -31,7 +31,7 @@ class MySession extends SessionHandler { } return parent::write($id, $data); } - public function close() { + public function close(): bool { $id = session_id(); if ($this->destroyed) { echo "(#$this->num) destroyed, cannot write\n"; diff --git a/ext/session/tests/session_set_save_handler_class_012.phpt b/ext/session/tests/session_set_save_handler_class_012.phpt index 2d55715544729..a6f53f6143026 100644 --- a/ext/session/tests/session_set_save_handler_class_012.phpt +++ b/ext/session/tests/session_set_save_handler_class_012.phpt @@ -15,14 +15,14 @@ echo "*** Testing session_set_save_handler() : incorrect arguments for existing class MySession extends SessionHandler { public $i = 0; - public function open($path, $name) { + public function open($path, $name): bool { ++$this->i; echo 'Open ', session_id(), "\n"; // This test was written for broken return value handling // Mimmick what was actually being tested by returning true here return (null === parent::open()); } - public function read($key) { + public function read($key): string|false { ++$this->i; echo 'Read ', session_id(), "\n"; return parent::read($key); diff --git a/ext/session/tests/session_set_save_handler_class_013.phpt b/ext/session/tests/session_set_save_handler_class_013.phpt index be701d3c5cb5e..1f8b5445cc4a9 100644 --- a/ext/session/tests/session_set_save_handler_class_013.phpt +++ b/ext/session/tests/session_set_save_handler_class_013.phpt @@ -14,17 +14,17 @@ echo "*** Testing session_set_save_handler() : incorrect arguments for existing class MySession extends SessionHandler { public $i = 0; - public function open($path, $name) { + public function open($path, $name): bool { ++$this->i; echo 'Open ', session_id(), "\n"; return parent::open($path, $name); } - public function read($key) { + public function read($key): string|false { ++$this->i; echo 'Read ', session_id(), "\n"; return parent::read($key); } - public function close() { + public function close(): bool { return parent::close(false); } } diff --git a/ext/session/tests/session_set_save_handler_class_016.phpt b/ext/session/tests/session_set_save_handler_class_016.phpt index 60654a49d60c0..d5e39c2292d30 100644 --- a/ext/session/tests/session_set_save_handler_class_016.phpt +++ b/ext/session/tests/session_set_save_handler_class_016.phpt @@ -15,7 +15,7 @@ echo "*** Testing session_set_save_handler() function: class with create_sid *** class MySession2 extends SessionHandler { public $path; - public function open($path, $name) { + public function open($path, $name): bool { if (!$path) { $path = sys_get_temp_dir(); } @@ -23,23 +23,23 @@ class MySession2 extends SessionHandler { return true; } - public function close() { + public function close(): bool { return true; } - public function read($id) { + public function read($id): string|false { return (string)@file_get_contents($this->path . $id); } - public function write($id, $data) { + public function write($id, $data): bool { return (bool)file_put_contents($this->path . $id, $data); } - public function destroy($id) { + public function destroy($id): bool { @unlink($this->path . $id); } - public function gc($maxlifetime) { + public function gc($maxlifetime): int|false { foreach (glob($this->path . '*') as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); @@ -48,7 +48,7 @@ class MySession2 extends SessionHandler { return true; } - public function create_sid() { + public function create_sid(): string { return parent::create_sid(); } } diff --git a/ext/session/tests/session_set_save_handler_class_017.phpt b/ext/session/tests/session_set_save_handler_class_017.phpt index 4cd100302f259..d68467e634530 100644 --- a/ext/session/tests/session_set_save_handler_class_017.phpt +++ b/ext/session/tests/session_set_save_handler_class_017.phpt @@ -15,7 +15,7 @@ echo "*** Testing session_set_save_handler() function: class with create_sid *** class MySession2 extends SessionHandler { public $path; - public function open($path, $name) { + public function open($path, $name): bool { if (!$path) { $path = sys_get_temp_dir(); } @@ -23,23 +23,23 @@ class MySession2 extends SessionHandler { return true; } - public function close() { + public function close(): bool { return true; } - public function read($id) { + public function read($id): string|false { return (string)@file_get_contents($this->path . $id); } - public function write($id, $data) { + public function write($id, $data): bool { return (bool)file_put_contents($this->path . $id, $data); } - public function destroy($id) { + public function destroy($id): bool { @unlink($this->path . $id); } - public function gc($maxlifetime) { + public function gc($maxlifetime): int|false { foreach (glob($this->path . '*') as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); @@ -48,7 +48,7 @@ class MySession2 extends SessionHandler { return true; } - public function create_sid() { + public function create_sid(): string { return pathinfo(__FILE__)['filename']; } } diff --git a/ext/session/tests/session_set_save_handler_class_018.phpt b/ext/session/tests/session_set_save_handler_class_018.phpt index dd1fe2129c8fe..01879ccc065f1 100644 --- a/ext/session/tests/session_set_save_handler_class_018.phpt +++ b/ext/session/tests/session_set_save_handler_class_018.phpt @@ -15,7 +15,7 @@ echo "*** Testing session_set_save_handler() function: class with validate_sid * class MySession2 extends SessionHandler { public $path; - public function open($path, $name) { + public function open($path, $name): bool { if (!$path) { $path = sys_get_temp_dir(); } @@ -23,23 +23,23 @@ class MySession2 extends SessionHandler { return true; } - public function close() { + public function close(): bool { return true; } - public function read($id) { + public function read($id): string|false { return (string)@file_get_contents($this->path . $id); } - public function write($id, $data) { + public function write($id, $data): bool { return file_put_contents($this->path . $id, $data)===FALSE ? FALSE : TRUE ; } - public function destroy($id) { + public function destroy($id): bool { @unlink($this->path . $id); } - public function gc($maxlifetime) { + public function gc($maxlifetime): int|false { foreach (glob($this->path . '*') as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); @@ -48,11 +48,11 @@ class MySession2 extends SessionHandler { return true; } - public function create_sid() { + public function create_sid(): string { return pathinfo(__FILE__)['filename']; } - public function validate_sid($id) { + public function validate_sid($id): bool { return pathinfo(__FILE__)['filename']===$id; } } diff --git a/ext/session/tests/session_set_save_handler_iface_001.phpt b/ext/session/tests/session_set_save_handler_iface_001.phpt index 53c99cfdb867a..e5aba2331c6a6 100644 --- a/ext/session/tests/session_set_save_handler_iface_001.phpt +++ b/ext/session/tests/session_set_save_handler_iface_001.phpt @@ -15,7 +15,7 @@ echo "*** Testing session_set_save_handler() function: interface ***\n"; class MySession2 implements SessionHandlerInterface { public $path; - public function open($path, $name) { + public function open($path, $name): bool{ if (!$path) { $path = sys_get_temp_dir(); } @@ -23,23 +23,23 @@ class MySession2 implements SessionHandlerInterface { return true; } - public function close() { + public function close(): bool { return true; } - public function read($id) { + public function read($id): string|false { return (string)@file_get_contents($this->path . $id); } - public function write($id, $data) { + public function write($id, $data): bool { return (bool)file_put_contents($this->path . $id, $data); } - public function destroy($id) { + public function destroy($id): bool { @unlink($this->path . $id); } - public function gc($maxlifetime) { + public function gc($maxlifetime): int|false { foreach (glob($this->path . '*') as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); diff --git a/ext/session/tests/session_set_save_handler_iface_002.phpt b/ext/session/tests/session_set_save_handler_iface_002.phpt index 10971a2b5f031..e661016705c61 100644 --- a/ext/session/tests/session_set_save_handler_iface_002.phpt +++ b/ext/session/tests/session_set_save_handler_iface_002.phpt @@ -13,18 +13,18 @@ ob_start(); echo "*** Testing session_set_save_handler() function: interface wrong ***\n"; interface MySessionHandlerInterface { - public function open($path, $name); - public function close(); - public function read($id); - public function write($id, $data); - public function destroy($id); - public function gc($maxlifetime); + public function open($path, $name): bool; + public function close(): bool; + public function read($id): string|false; + public function write($id, $data): bool; + public function destroy($id): bool; + public function gc($maxlifetime): int|false; } class MySession2 implements MySessionHandlerInterface { public $path; - public function open($path, $name) { + public function open($path, $name): bool { if (!$path) { $path = sys_get_temp_dir(); } @@ -32,28 +32,31 @@ class MySession2 implements MySessionHandlerInterface { return true; } - public function close() { + public function close(): bool { return true; } - public function read($id) { + public function read($id): string|false { return (string)@file_get_contents($this->path . $id); } - public function write($id, $data) { + public function write($id, $data): bool { echo "Unsupported session handler in use\n"; + return false; } - public function destroy($id) { + public function destroy($id): bool { @unlink($this->path . $id); + return true; } - public function gc($maxlifetime) { + public function gc($maxlifetime): int|false { foreach (glob($this->path . '*') as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); } } + return true; } } diff --git a/ext/session/tests/session_set_save_handler_iface_003.phpt b/ext/session/tests/session_set_save_handler_iface_003.phpt index 582942f185eb4..43cdb986f2f22 100644 --- a/ext/session/tests/session_set_save_handler_iface_003.phpt +++ b/ext/session/tests/session_set_save_handler_iface_003.phpt @@ -15,7 +15,7 @@ echo "*** Testing session_set_save_handler() function: id interface ***\n"; class MySession2 implements SessionHandlerInterface, SessionIdInterface { public $path; - public function open($path, $name) { + public function open($path, $name): bool { if (!$path) { $path = sys_get_temp_dir(); } @@ -23,33 +23,34 @@ class MySession2 implements SessionHandlerInterface, SessionIdInterface { return true; } - public function close() { + public function close(): bool { return true; } - public function read($id) { + public function read($id): string|false { return (string)@file_get_contents($this->path . $id); } - public function write($id, $data) { + public function write($id, $data): bool { // Empty $data = 0 = false return (bool)file_put_contents($this->path . $id, $data); } - public function destroy($id) { + public function destroy($id): bool { @unlink($this->path . $id); } - public function gc($maxlifetime) { + public function gc($maxlifetime): int|false { foreach (glob($this->path . '*') as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); } } + return true; } - public function create_sid() { + public function create_sid(): string { return pathinfo(__FILE__)['filename']; } } diff --git a/ext/session/tests/session_set_save_handler_sid_001.phpt b/ext/session/tests/session_set_save_handler_sid_001.phpt index 76d3f256bf7e3..ffb54af1d33b7 100644 --- a/ext/session/tests/session_set_save_handler_sid_001.phpt +++ b/ext/session/tests/session_set_save_handler_sid_001.phpt @@ -15,7 +15,7 @@ echo "*** Testing session_set_save_handler() function: create_sid ***\n"; class MySession2 { public $path; - public function open($path, $name) { + public function open($path, $name): bool { if (!$path) { $path = sys_get_temp_dir(); } @@ -23,24 +23,24 @@ class MySession2 { return true; } - public function close() { + public function close(): bool { return true; } - public function read($id) { + public function read($id): string|false { return (string)@file_get_contents($this->path . $id); } - public function write($id, $data) { + public function write($id, $data): bool { // Empty $data = 0 = false return (bool)file_put_contents($this->path . $id, $data); } - public function destroy($id) { + public function destroy($id): bool { @unlink($this->path . $id); } - public function gc($maxlifetime) { + public function gc($maxlifetime): int|false { foreach (glob($this->path . '*') as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); @@ -49,7 +49,7 @@ class MySession2 { return true; } - public function create_sid() { + public function create_sid(): string { return pathinfo(__FILE__)['filename']; } } diff --git a/ext/session/tests/session_set_save_handler_sid_002.phpt b/ext/session/tests/session_set_save_handler_sid_002.phpt index 6321c5a5681c8..54bfd1e27ff5f 100644 --- a/ext/session/tests/session_set_save_handler_sid_002.phpt +++ b/ext/session/tests/session_set_save_handler_sid_002.phpt @@ -16,7 +16,7 @@ echo "*** Testing session_set_save_handler() function: create_sid ***\n"; class MySession2 { public $path; - public function open($path, $name) { + public function open($path, $name): bool { if (!$path) { $path = sys_get_temp_dir(); } @@ -24,23 +24,24 @@ class MySession2 { return true; } - public function close() { + public function close(): bool { return true; } - public function read($id) { + public function read($id): string|false { return @file_get_contents($this->path . $id); } - public function write($id, $data) { + public function write($id, $data): bool { return file_put_contents($this->path . $id, $data); } - public function destroy($id) { + public function destroy($id): bool { @unlink($this->path . $id); + return false; } - public function gc($maxlifetime) { + public function gc($maxlifetime): int|false { foreach (glob($this->path . '*') as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); @@ -49,8 +50,9 @@ class MySession2 { return true; } + #[ReturnTypeWillChange] public function create_sid() { - return null; + return false; } }