Skip to content

Commit 2642b63

Browse files
committed
Fix session native issue
1 parent a0411a0 commit 2642b63

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Bridge/NativeBridge.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class NativeBridge implements BridgeInterface
1717

1818
protected HandlerInterface $handler;
1919

20+
public protected(set) ?array $storageBackup = null;
21+
2022
/**
2123
* NativeBridge constructor.
2224
*
@@ -153,6 +155,8 @@ public function regenerate(bool $deleteOld = false, bool $saveOld = true): bool
153155
*/
154156
public function writeClose(bool $unset = true): bool
155157
{
158+
$this->storageBackup = $_SESSION;
159+
156160
$result = session_write_close();
157161

158162
if ($unset) {
@@ -169,6 +173,8 @@ public function writeClose(bool $unset = true): bool
169173
*/
170174
public function destroy(): void
171175
{
176+
$this->storageBackup = $_SESSION;
177+
172178
if ($this->getId()) {
173179
session_unset();
174180
session_destroy();
@@ -182,6 +188,10 @@ public function destroy(): void
182188
*/
183189
public function &getStorage(): mixed
184190
{
191+
if ($this->storageBackup !== null) {
192+
return $this->storageBackup;
193+
}
194+
185195
return $_SESSION;
186196
}
187197

src/Session.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public function start(): bool
117117
return true;
118118
}
119119

120+
if ($this->bridge instanceof NativeBridge && headers_sent()) {
121+
return $this->bridge->isStarted();
122+
}
123+
120124
$this->registerINI();
121125

122126
if (
@@ -400,8 +404,6 @@ public function clear(): bool
400404

401405
public function &all(): array
402406
{
403-
$this->start();
404-
405407
return $this->getStorage();
406408
}
407409

0 commit comments

Comments
 (0)