-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Handle indirect zvals in SplFixedArray::__serialize #10925
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still very much confused as to what indirect zvals are, but LGTM! :)
Thanks for reviewing.
Basically the same as a reference, but without a refcount and for internal use only. Used here for the dynamic properties table. |
Ahhh okay so "internal reference" is how I'll keep this in mind then, but I wonder if we are not missing indirect zvals in a lot of potential other places :/ |
I found an additional problem that already existed, but got worse when I tried fixing the original problem of this PR. The wrong hashtable was used. It can still be stale. We should really use the object properties hash table (see my latest commit). |
} ZEND_HASH_FOREACH_END(); | ||
} | ||
ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, key, current) { | ||
if (key != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please describe me when the key is null? I wasn't be able to understand it 100% based on the comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see I removed the comment, I need to place that back.
In any case: if var_dump (or something else that rebuilds the properties table) has been called before serialize(), then the properties table will include entries for the array elements. In those cases the key == NULL, and h == the index of the element.
For example:
<?php
$test = new SplFixedArray(2);
var_dump($test);
var_dump(serialize($test)); // If you add a printf to the foreach loop you'll see that the entries for array index 0 and 1 are also printed. But this does not happen if you remove the preceding var_dump, because then the properties table hasn't been rebuilt yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the difference between this version of the patch and the original is the following:
In the original patch I only added support for the INDIRECT zvals by appending _IND.
Shortly after merging I noticed a problem, so I reverted the merge and re-opened this PR.
The problem I noticed is that the code was using the wrong HashTable, their entries could still be stale (see the most recent commit which adds a testcase for this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! The new code comment is very helpful!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we weren't actually using the object properties but just what SPL kept track off?
Still looks sensible and good to me. But clarifying the NULL key case might be good. :)
Indeed. |
0e87885
to
fb8a469
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think we are finally good to merge this!
Thanks. I think I'll wait a bit until @kocsismate also reviews, I don't want to do another merge-revert dance 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for the review to you both :) I'm going to change the commit title on merge though, because it does more than fixing indirect zvals as it also fixes the stale property problem. |
Follow-up for GH-10907 and GH-10921.
I didn't notice it at first but there's another issue that was introduced in 8.2: INDIRECT zvals are not handled properly and so the serialization doesn't contain their value. I didn't notice that when writing my test, sorry about that.