-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP Deprecated: Calling session_set_save_handler() in PHP 8.4
.
#20140
Comments
https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#session_set_save_handler
|
class SessionHandlerInterface {
/* Métodos */
abstract public close(): bool
abstract public destroy(string $session_id): bool
abstract public gc(int $maxlifetime): int
abstract public open(string $save_path, string $session_name): bool
abstract public read(string $session_id): string
abstract public write(string $session_id, string $session_data): bool
} I will have to add these new methods, and call the old ones the new methods, is it the only way to not break bc? |
Seems so. |
We could create a separate decorator class to avoid adding more methods to |
This could be a solution to resolve this issue. <?php
namespace yii\web;
use SessionHandlerInterface;
class SessionHandler implements SessionHandlerInterface
{
private Session $session;
public function __construct(Session $session)
{
$this->session = $session;
}
/**
* @inheritDoc
*/
public function open(string $savePath, string $sessionName): bool
{
return $this->session->openSession($savePath, $sessionName);
}
/**
* @inheritDoc
*/
public function close(): bool
{
return $this->session->closeSession();
}
/**
* @inheritDoc
*/
public function read(string $id): string
{
return $this->session->readSession($id);
}
/**
* @inheritDoc
*/
public function write(string $id, string $data): bool
{
return $this->session->writeSession($id, $data);
}
/**
* @inheritDoc
*/
public function destroy(string $id): bool
{
return $this->session->destroySession($id);
}
/**
* @inheritDoc
*/
public function gc(int $maxlifetime): int|false
{
return $this->session->gcSession($maxlifetime);
}
} class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Countable
/**
* @var SessionHandlerInterface|array|null an object implementing the SessionHandlerInterface or a configuration array.
* If set, will be used to provide persistency instead of build-in methods.
*/
public SessionHandlerInterface|array|null $handler = null;
/**
* Registers session handler.
*
* @throws \yii\base\InvalidConfigException
*/
protected function registerSessionHandler()
{
$sessionModuleName = session_module_name();
if (static::$_originalSessionModule === null) {
static::$_originalSessionModule = $sessionModuleName;
}
if ($this->handler === null && $this->getUseCustomStorage()) {
$this->handler = Yii::createObject(
[
'__class' => SessionHandler::class,
'__construct()' => [$this],
]
);
}
if ($this->handler !== null) {
if (is_array($this->handler)) {
$this->handler = Yii::createObject($this->handler);
}
if (!$this->handler instanceof SessionHandlerInterface) {
throw new InvalidConfigException(
'"' . get_class($this) . '::handler" must implement the SessionHandlerInterface.'
);
}
YII_DEBUG
? session_set_save_handler($this->handler, false) : @session_set_save_handler($this->handler, false);
} elseif (
$sessionModuleName !== static::$_originalSessionModule
&& static::$_originalSessionModule !== null
&& static::$_originalSessionModule !== 'user'
) {
session_module_name(static::$_originalSessionModule);
}
}
} |
faced this issue when tried out released php 8.4.1 |
For reference, docker test failures with PHP 8.4: https://github.com/yiisoft/yii2-docker/actions/runs/12030640738/job/33538471452 (a lot of session related stuff) Tests in yii2 repo are green, but output shows also a lot of errors: https://github.com/yiisoft/yii2/actions/runs/12004863459/job/33460517449 |
PHP Deprecated: Calling session_set_save_handler() with more than 2 arguments is deprecated in /home/runner/work/yii2/yii2/framework/web/Session.php on line 187
@rob006 @samdark @bizley
This is the last error we have left in PHP 8.4, which would be the best way to fix it.
The text was updated successfully, but these errors were encountered: