-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Portable UTF-8 #38
base: refactoring
Are you sure you want to change the base?
Portable UTF-8 #38
Conversation
…lder, test results are the same
# Conflicts: # composer.json
Finally managed to provide Drone CI with the locales needed to conduct the string comparision tests. |
please provide a PR against our docker-images repo and include the locales when this PR is merged and remove it from here. |
I see you are changing some function signatures which I would say is not allowed because of b/c, Also you deprecated the utf8 functions say as alternative to use UTF8::XXX (I think you mean voku\helper\UTF8) which means the cms has to load the dependency directly? If you replace this lib again with something new and remove the dependency here the cms would fail right? |
This pull request, as is, necessitates a major release. Why do I care? Because my company still uses this product and the last thing I need is to work around broken releases with major compatibility breaks or explain to our customers why we are freezing code updates for their websites.
Additional nitpicks:
|
Signatures below src/ should only have changed in a compatible way; if there are breaking changes, it needs to be corrected.
AFAIK, the Portable UTF-8 library is already part of the CMS indirectly (see issue comment).
That should not happen, hence the deprecation. But, of course, it can and should be discussed |
Thank you for your feedback, which I appreciate very much!
I neither knew nor expected that the underlying library's API became part of the package's API. The whole point with providing a facade is to avoid this. So that's something we need to discuss thoroughly.
Those changes should be restricted to the docblocks, not the signature itself. If a signature is affected in code, it needs to be corrected.
This should be covered by the tests; if something's missing, the tests are separated from this PR, so they can be applied to both old and new code.
The method in question has no type check and always accepted both strings and arrays of strings. Only thing changed here is the docblock, i.e., documentation.
Agree - those are overlooked residues. |
Docs - Add change of default values to inline documentation
# Conflicts: # src/StringHelper.php
Refactor - Set default to 0 in strpos and strrpos
Answered in the discussion, but the TL;DR is that StringHelper can be refactored without issue but
When the API lacks typed signatures, the doc block is the contract for the signature. So, even removing a type from the doc blocks can be considered a B/C break as you are declaring that a previously supported type is no longer supported.
So, there are two things in this comment:
This was the return types, not the parameter types. Again, lacking types in the PHP code itself, the doc block acts as the contract. An example is with |
I get your point, but I'm not sure if I agree. Since the PHP interpreter does not look at the doc block, the doc block IMHO only serves documentation purposes. If I want the consumer to either omit an argument or provide an integer, I tell them in the doc block that the argument is an optional integer. The fact, that the code might need a null value to detect omission, is an internal (implementation) problem, but should not "pollute" the signature. Am I wrong?
StringHelper::str_ireplace() returns an array only, if you provide an array as subject, it will always return a string, if subject is a string. Thus in this case, yes, the type is widened, but it should not affect existing code. |
Then by that argument, any untyped parameter must accept all types without generating a runtime error. If I pass an array into a parameter documented as only supporting a string or an integer, am I wrong for violating the types in the documentation, or is the code wrong for not correctly handling all potential types since a type is not enforced at the language level? This is why a doc block should be considered part of the API contract.
IMO, yes. <?php declare(strict_types=1);
function add_up_to_three_numbers(int|float $number1, int|float $number2, int|float $number3 = null): int|float
{
$return = $number1 + $number2;
if ($number3 !== null) {
$return += $number3;
}
return $return;
} While this actually is legal on PHP 8.0, to me this is an invalid function signature as it reads that each parameter MUST be an integer or float with no nullability. The way PHP interprets things, null is allowed even though the parameter's type is not declared nullable. With an explicit nullable declaration (i.e. Until PHP 8, you have to pass all arguments if you want to set a value on any optional argument, so something like
That entire example might have been a poor one to use, but hopefully, it conveyed my point; widening the potential return values absolutely can have B/C concerns for downstream users and needs to be treated with care. |
Pull Request for Issue #29
This pull request replaces the abandoned library
phputf8
with Portable UTF-8.(Freely quoted from Portable UTF-8)
This PR is kept separate from the Test Consolidation #37 for now, so the tests can be updated and used for both new and old implementation, if issues arise.
Summary of Changes
phputf8
withPortable UTF-8
Testing Instructions
Documentation Changes Required
Yes, but should be generated from source. Inline documentation has been revised.
Outstanding Decisions