Skip to content

fix: serialize stdClass dynamic properties in Json::add()#65

Merged
usernane merged 2 commits into
devfrom
fix/54-stdclass-serialization
Jun 8, 2026
Merged

fix: serialize stdClass dynamic properties in Json::add()#65
usernane merged 2 commits into
devfrom
fix/54-stdclass-serialization

Conversation

@usernane

@usernane usernane commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

Fix Json::add() to correctly serialize stdClass objects by reading their dynamic properties via get_object_vars().

Motivation

Users returning stdClass objects (e.g. via (object)[...] cast) get empty {} in JSON output. Fixes #54.

Changes

  • Added failing test cases that reproduce the bug

How to Test / Verify

Unit tests: testStdClassSerialization and testStdClassInArray in JsonTest.php. Currently failing, confirming the bug.

Breaking Changes and Migration Steps

None

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed) Docs Repo
  • I ran lint/cs-fixer (if applicable) (composer fix-cs)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #54

Ibrahim BinAlshikh added 2 commits June 8, 2026 23:51
stdClass objects have dynamic properties that are not visible to
ReflectionClass::getProperties(). Add an early return that converts
them using get_object_vars() so their properties are serialized.

Closes #54
@sonarqubecloud

sonarqubecloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

@usernane usernane merged commit 1e0f0c1 into dev Jun 8, 2026
5 of 7 checks passed
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.

1 participant