php 8 - substr returns an empty string when string is less than start characters long in PHP 8
Get the solution ↓↓↓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)?
Answer
Solution:
It seems like this was an intentional change as mentioned in https://php.watch/versions/8.0/substr-out-of-bounds
and implemented here:
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: script cache:clear returned with error code 255
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.