IntlBreakIterator::create methods cannot returns null#21004
IntlBreakIterator::create methods cannot returns null#21004VincentLanglet wants to merge 2 commits intophp:PHP-8.4from
Conversation
|
Hi I ll have a look later but please target PHP-8.4 instead. |
d596d29 to
4188693
Compare
I was looking at the right branch and found https://github.com/php/php-src/blob/master/CONTRIBUTING.md#git-commit-rules which was saying I update the PR and #21003 too then. |
|
Are you sure this should target 8.4? This class is not final, and this would be LSP breaking. |
Oh maybe I missunderstood this code ? I thought this was just a "stub" which has no real meaning for the php codebase except giving documentation for the php-doc website (or tool with auto generated doc like phpstorm). Maybe you prefer I add phpdoc with a return tag instead ? |
|
So I looked, in theory it is possible for these to return null, in practice however it is pretty difficult to actually happen => bad/corrupted ICU database, broken ICU version, OOM ... but those are quite unlikely. Giving a bad locale does not work as you mentioned. |
|
Right, but even if this is unlikely, code overriding these methods and currently return nullable will break with an LSP error. That's not something that should happen in a patch. |
|
yes I was not gonna accept these changes |
|
@VincentLanglet To answer your question: Stubs are used for reflection, but also LSP (i.e. subtyping rules for parameters / return types). So, for methods that could be overridden, types should generally only change in |
|
Ok, then even if it's unlikely it's "possible" and I should close the PR or should I "just" target master instead ? Also, what about #21003 @devnexen @iluuu1994 ? Should I target master or is it considered as a real fix ? I feel like the current type is wrong in the stub. |
|
If it's even theoretically possible that these functions will return a value, it should be reflected accordingly. Otherwise, it would need to be ensured that these values aren't returned, e.g. by throwing an exception instead. |
Hi,
I may be wrong but I feel like the stub is wrong about the fact those create method can returns null.
All the example I found are not checking null and when checking lot of non-locale values
I still get an IntlBreakIterator instance.
So I wonder if the stub is not wrong.