Running MW master updater on PHP master:
Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::open($save_path, $session_name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/session/PHPSessionHandler.php on line 181 Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/session/PHPSessionHandler.php on line 196 Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::read($id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/session/PHPSessionHandler.php on line 210 Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::write($id, $dataStr) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/session/PHPSessionHandler.php on line 238 Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::destroy($id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/session/PHPSessionHandler.php on line 344 Deprecated: Return type of MediaWiki\Session\PHPSessionHandler::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/session/PHPSessionHandler.php on line 365 Deprecated: Return type of Wikimedia\Rdbms\IResultWrapper::seek($pos) should either be compatible with SeekableIterator::seek(int $offset): void, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/libs/rdbms/database/resultwrapper/IResultWrapper.php on line 59 Deprecated: Return type of Wikimedia\Rdbms\IResultWrapper::current() should either be compatible with Iterator::current(): mixed, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/libs/rdbms/database/resultwrapper/IResultWrapper.php on line 72 Deprecated: Return type of Wikimedia\Rdbms\IResultWrapper::next() should either be compatible with Iterator::next(): void, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/libs/rdbms/database/resultwrapper/IResultWrapper.php on line 83 Deprecated: Return type of Wikimedia\Rdbms\IResultWrapper::key() should either be compatible with Iterator::key(): mixed, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/libs/rdbms/database/resultwrapper/IResultWrapper.php on line 77 Deprecated: Return type of Wikimedia\Rdbms\ResultWrapper::valid() should either be compatible with Iterator::valid(): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/libs/rdbms/database/resultwrapper/ResultWrapper.php on line 177 Deprecated: Return type of Wikimedia\Rdbms\ResultWrapper::rewind() should either be compatible with Iterator::rewind(): void, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in includes/libs/rdbms/database/resultwrapper/ResultWrapper.php on line 157
From my experiments, just slapping return types on MW interfaces avoids the notice on PHP 8.1 and is backwards-compatible with 7.2+. Starting with 7.4, parameter types can be added too.
See also: https://wiki.php.net/rfc/internal_method_return_types