- This topic has 5 replies, 1 voice, and was last updated 2 months ago by donatj.
- AuthorPosts
- November 18, 2020 at 8:20 pm #2583ayeshrajansParticipant
[PHP 8] `substr` returns empty string on offsets larger than string. It was `false` before
November 18, 2020 at 8:20 pm #2584[deleted]Guest[deleted]
November 18, 2020 at 8:20 pm #2585jkoudysGuestI’m somewhat divided on this one. Limiting mixed-type returns is usually easier to reason about, and the `false` feels legacy as the standard mixed type for this kind of thing nowadays is a null. On the other hand, you’re losing useful information since substrings could be made with an equal start and end that would be empty, while if they were beyond the length before would’ve been false.
November 18, 2020 at 8:20 pm #2586DaDeatherGuestI’m quite irritated or am I missing something here?
Look at this:
https://3v4l.org/3H05iThe only thing I can see has changed is the `grapheme_substr` but everything else is the same.
November 18, 2020 at 8:20 pm #2588nikicGuestWorth noting is that this behavior is specific to substr(), to make certain usages painless (like “take (at most) the first N bytes of a string”). Pretty much everything else will throw ValueError on out of bounds offsets or lengths.
November 18, 2020 at 8:20 pm #2589donatjGuestTo me, blindly ignoring failures like this is the worst option. Seems like they should have just corrected the documentation but instead chose the nuclear option.
- AuthorPosts
- You must be logged in to reply to this topic.