Reputation: 1577
The PHP docs for substr()
says:
If string is less than start characters long, FALSE will be returned.
and gives the example
$rest = substr("abcdef", 4, -4); // returns false
Interestingly this seems to be not true starting with PHP 8.0.0rc1 as in newer versions the function returns an empty string instead:
Is this a bug in PHP or an undocumented change (or am I misunderstanding something)?
Upvotes: 0
Views: 460
Reputation: 1577
It seems like this was an intentional change as mentioned in https://php.watch/versions/8.0/substr-out-of-bounds
and implemented here:
https://github.com/php/php-src/pull/6182
Upvotes: 3