Open
Conversation
Owner
|
In PHP unserializing that object results in an Array with two elements, both which are the the same object. Modifications to either element modify both elements. php > $u = unserialize('a:2:{i:0;s:3:"foo";i:1;R:2;}');
php > print_r($u);
Array
(
[0] => foo
[1] => foo
)
php > $u[0] .= "bar";
php > print_r($u);
Array
(
[0] => foobar
[1] => foobar
)Shouldn't the Ruby version do the same instead of making a ruby> u = PHP.unserialize('a:2:{i:0;s:3:"foo";i:1;R:2;}');
=> ["foo", "foo"]
ruby> u[0] << "bar"
=> "foobar"
ruby> u
=> ["foobar", "foobar"] |
Contributor
Author
|
Reading your reply, I also noticed the level of support is crucially insufficient in production.
deserialized = PHP.unserialize(
# $a = (object)[]; echo serialize([$a,$a]);
'a:2:{i:0;O:8:"stdClass":0:{}i:1;r:2;}' # <== needs support for "r"
)
deserialized.unshift "foo" # <== breaks `nth` of "r:nth"I would try another PR or improve this branch. |
fcd0f49 to
9ba7966
Compare
Contributor
Author
|
I have improved the patch. Could you take a look?
|
Contributor
Author
|
Please be noted that the improved patch enables "Modifications to either element modify both elements." def test_reference_of_object
# ...
assert_same unserialized[0], unserialized[1] |
9ba7966 to
fd667cd
Compare
Contributor
Author
|
Rebased on v1.4.1 |
|
do we have an update on this PR if it pass 'tests' ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
While the "R" (Reference) type rarely appears in real-world PHP serialization, certain applications may use it. (at least I met it and saw
Unable to unserialize type 'R'error.)This pull request introduces support for the "R" type by adding the PHP::Reference object,
which can be re-serialized to what it was before unserializing.