- This topic has 5 replies, 1 voice, and was last updated 2 months ago by donatj.
- November 18, 2020 at 8:20 pm #2583ayeshrajansParticipant
[PHP 8] `substr` returns empty string on offsets larger than string. It was `false` beforeNovember 18, 2020 at 8:20 pm #2584[deleted]Guest
[deleted]November 18, 2020 at 8:20 pm #2585jkoudysGuest
I’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 #2586DaDeatherGuest
I’m quite irritated or am I missing something here?
Look at this:
The only thing I can see has changed is the `grapheme_substr` but everything else is the same.November 18, 2020 at 8:20 pm #2588nikicGuest
Worth 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 #2589donatjGuest
To 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.
- You must be logged in to reply to this topic.