Introduce PHP::PhpObject to handle repeating stdClass with different property sets #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
stdClass object may appears twice or more with difference properties as shown in the example below:
However, the current implementation creates
Struct::stdClass
class with only thefoo
memberwhen it met the first serialized object.
Then during processing the 2nd object, it tries to instantiate
Struct::stdClass
with properties set["bar" => 2]
,and this ends up
undefined method bar=
error.Solution
I introduced a new
PHP::PhpObject
class to represent an unserialized object instead of using Struct.This is a subclass of OpenStruct so that it can accept any property assignments from serialized objects.
Also it can be re-serialized to what it was before unserializing, keeping both the properties order and the object's class name. (stored in
PhpObject#_php_classname
)