Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions features/access.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ Feature: Session access
Scenario: Iterate over non-populated session
When data does not exist
Then data is not iterated
Scenario: Overload the Session object
When data does not exist
Then array overloading succeeds
And object overloading succeeds
4 changes: 2 additions & 2 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(string $name, ?string $id = null, array $contents =
*
* @throws RuntimeException if not initialized
*/
public function __get(string $name)
public function &__get(string $name)
{
if (!$this->isInitialized()) {
throw new RuntimeException('Session not initialized');
Expand Down Expand Up @@ -133,7 +133,7 @@ public function offsetUnset($name): void
unset($this->contents[$name]);
}

public function offsetGet($name): mixed
public function &offsetGet($name): mixed
{
if (!$this->isInitialized()) {
throw new RuntimeException('Session not initialized');
Expand Down
38 changes: 36 additions & 2 deletions tests/behavior/AccessContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function propertyReadTriggersNoticeError(): void
{
try {
$errorThrown = false;
$bar = $this->session->bar;
$bar = clone $this->session->bar;
// @phpstan-ignore-next-line
} catch (Throwable $e) {
$errorThrown = true;
Expand Down Expand Up @@ -133,7 +133,7 @@ public function arrayAccessReadTriggersNoticeError(): void
{
try {
$errorThrown = false;
$bar = $this->session['bar'];
$bar = clone $this->session['bar'];
// @phpstan-ignore-next-line
} catch (Throwable $e) {
$errorThrown = true;
Expand Down Expand Up @@ -199,4 +199,38 @@ public function iteratorFails(): void

Assert::assertSame(0, $counter);
}

/**
* @Then array overloading succeeds
*/
public function arrayOverloadSucceeds(): void
{
$error = false;

try {
$this->session['overload_me'] = [];
$this->session['overload_me'][] = 'foo';
} catch (\Exception $ex) {
$error = true;
}

Assert::assertFalse($error);
}

/**
* @Then object overloading succeeds
*/
public function objectOverloadSucceeds(): void
{
$error = false;

try {
$this->session->overload_me = [];
$this->session->overload_me[] = 'foo';
} catch (\Exception $ex) {
$error = true;
}

Assert::assertFalse($error);
}
}