Skip to content

Improve virtual property support#1164

Open
jivanf wants to merge 4 commits intospatie:mainfrom
jivanf:improve-virtual-property-support
Open

Improve virtual property support#1164
jivanf wants to merge 4 commits intospatie:mainfrom
jivanf:improve-virtual-property-support

Conversation

@jivanf
Copy link
Copy Markdown

@jivanf jivanf commented Mar 16, 2026

This PR solves the following issues related to data classes with virtual properties:

  • Virtual properties aren't computed by default: A virtual property must always be computed because it can never be assigned a value. DataPropertyFactory now checks the attribute and if the property is virtual using isVirtual() (when it's available).
  • Data objects with virtual properties can't be serialized: Virtual properties are currently included in the serialized properties returned by __sleep() in BaseData. However, virtual properties can't be serialized. These properties are now excluded from the array returned by __sleep().

It's important to note that this only applies to virtual properties. Backed properties with hooks don't need to be computed and can be serialized. Tests were added to ensure backed properties with hooks aren't treated as virtual properties.

jivanf added 4 commits March 15, 2026 19:47
`serialize()` throws an error if virtual properties are returned by `__sleep()`. This commit excludes them from the returned array.
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