-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support "R" (Reference) type #18
base: master
Are you sure you want to change the base?
Conversation
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"] |
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
I have improved the patch. Could you take a look?
|
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
Rebased on v1.4.1 |
do we have an update on this PR if it pass 'tests' ? |
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.