-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix 8.1 serialization #43
Conversation
This reverts commit abebab9.
Only for php8.1+. Calling the old php functions instead of mimicking the code. This is slower, but the code is simpler, and here we are only talking about when you run (un)serialize() function. The new serialize methods should throw on error. Issue: phpGH-42
Because we changed the output of the serialization in version 8.1
Copy old tests with fixes to output
Shows that the old serialized string works, and it results in the same code as the new format. Also, show that __serialize() method returns an array with 'xml' key
@cmb69 I wonder if you can review this code for me? |
I'll try to have a closer look tomorrow, but I strongly suggest to set up some CI. Likely GH actions would be the best solution. Also consider to introduce stub files. These can be used to build the required arginfo structures automatically. |
Awesome. Thank you!
It is planned, and is pretty much next on my todo list.
Sounds good. I will take a look. |
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.
This looks good to me, but I've left some suggestions for your consideration.
src/php7/php_solr_document.c
Outdated
RETURN_THROWS(); | ||
} | ||
array_init(return_value); | ||
add_assoc_stringl(return_value, "xml", Z_STRVAL(serialized), Z_STRLEN(serialized)); |
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.
This could be simplified:
add_assoc_stringl(return_value, "xml", Z_STRVAL(serialized), Z_STRLEN(serialized)); | |
add_assoc_str(return_value, "xml", serialized); |
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.
Nice. Since serialized
is a zval
I used add_assoc_zval
src/php7/php_solr_document.c
Outdated
zend_string *key_str = zend_string_init("xml", sizeof("xml") -1, 1); | ||
zend_object *object = NULL; | ||
zval *tmp = NULL; | ||
/* Process the parameters passed to the default constructor */ |
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.
"default constructor" sounds wrong. Maybe just drop the comment?
src/php7/php_solr_params.c
Outdated
RETURN_THROWS(); | ||
} | ||
array_init(return_value); | ||
add_assoc_stringl(return_value, "xml", Z_STRVAL(serialized), Z_STRLEN(serialized)); |
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.
add_assoc_stringl(return_value, "xml", Z_STRVAL(serialized), Z_STRLEN(serialized)); | |
add_assoc_str(return_value, "xml", serialized); |
@@ -180,6 +180,12 @@ ZEND_BEGIN_ARG_INFO(SolrDocument_unserialize_args, 0) | |||
ZEND_ARG_INFO(0, serialized) | |||
ZEND_END_ARG_INFO() | |||
|
|||
#if PHP_VERSION_ID >= 80100 |
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.
If you want to preserve full BC with PHP < 8.1, this looks right. If, on the other hand, that would not be necessary, you could do all the new PHP 8.1 stuff unconditionally. Prior to PHP 7.4.0, it would be ignored; as of PHP 7.4.0, Serializable
would be ignored.
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.
Well, here I had many problems. I ended up with only breaking BC for 8.1 (I guess I am not really breaking anything since we were not really supporting 8.1).
- If both
serialize()
and__serialize()
are available PHP will pick the new one in 7.4+. Those two create totally different outputs, as seen in the tests I duplicated instead of changed because of this difference. - Method signature for
zend_call_method()
was changed in 8.0. So, I would have had to deal with that mismatch somehow. - This extension uses the unserialization process to create objects from the XML responses, so I don't really dare to change things too much :)
@@ -0,0 +1,50 @@ | |||
--TEST-- |
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.
Consider not to split the tests; it might be okay to use some placeholders for the version-dependent parts (if all else fails, you can use regular expressions inside of %r
markers, e.g. %rC:20:"SolrModifiableParams"|O:12:"SolrDocument"%r
).
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 kinda like having the tests split because I am going with the different api for 8.1+.
Also, the difference in the serialization output is quite different between the old and the new.
C:12:"SolrDocument":172:{<?xml version="1.0" encoding="UTF-8"?>
vs.
O:12:"SolrDocument":1:{s:3:"xml";s:172:"<?xml version="1.0" encoding="UTF-8"?>
And then also the ending.
print_r(unserialize($serializedString)->toArray()); | ||
?> | ||
--EXPECT-- | ||
O:12:"SolrDocument":1:{s:3:"xml";s:172:"<?xml version="1.0" encoding="UTF-8"?> |
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.
Generally, avoid hard-coded string lengths in tests if there are line-breaks; this might not work on Windows (LF vs. CRLF). Instead you can use a placeholder:
O:12:"SolrDocument":1:{s:3:"xml";s:172:"<?xml version="1.0" encoding="UTF-8"?> | |
O:12:"SolrDocument":1:{s:3:"xml";s:%d:"<?xml version="1.0" encoding="UTF-8"?> |
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 agree, but I don't want to change these tests, they are old and tried (I hope).
@remicollet might have some thoughts about this, too, since he noted that #30 breaks BC. |
See issue #42 for information.
This fixes tests for all versions after 8.1 compatibility fixes.