Skip to content

fix(session): initialize $data property with default empty array#274

Open
woprrr wants to merge 1 commit intomodelcontextprotocol:mainfrom
woprrr:fix/session-data-initialization
Open

fix(session): initialize $data property with default empty array#274
woprrr wants to merge 1 commit intomodelcontextprotocol:mainfrom
woprrr:fix/session-data-initialization

Conversation

@woprrr
Copy link
Copy Markdown

@woprrr woprrr commented Apr 2, 2026

Summary

  • Initialize Session::$data with = [] to prevent TypeError when the property is accessed before initialization on a newly created session
  • Replace isset($this->data) check in readData() with an explicit $loaded flag to preserve lazy loading from the session store
  • Set $loaded = true in clear() and hydrate() to maintain consistent state

Fixes #273

Test plan

  • All 28 existing SessionTest tests pass
  • PHPStan level 6 with no errors
  • PHP-CS-Fixer with no violations
  • testSaveBeforeReadInitializesData confirms save() on a fresh session works
  • testSessionLoadsDataFromStoreOnConstruction confirms lazy loading still works

Prevents TypeError when $data is accessed before initialization on a
newly created session. Replaces the isset($this->data) check in
readData() with an explicit $loaded flag to preserve lazy loading
from the session store.

Fixes modelcontextprotocol#273
@woprrr woprrr force-pushed the fix/session-data-initialization branch from 855dd2b to 9e2023d Compare April 2, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session::save() crashes when $data property is never initialized

1 participant