|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-06-25 08:44 UTC] thekid@php.net
Description:
------------
The substr() function behaves differently in a current PHP7 than e.g. in alpha1
Test script:
---------------
substr("Hello", 5, 1)
Expected result:
----------------
false
Actual result:
--------------
""
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 06:00:01 2025 UTC |
I believe this is what's causing the change: @@ -2406,7 +2407,7 @@ PHP_FUNCTION(substr) } } - if (f >= (zend_long)str->len) { + if (f > (zend_long)str->len) { RETURN_FALSE; } ...which was introduced in 257054e81d4dad73bf9d09cd206d3a6727ad1777 to fix #62922 Hrm.This change is intentional. The behavior is of course BS, but this is because strpos() in general returns BS. E.g. substr("Hello", 4, 20) has always returned "o" rather than throwing an error. The change only allowed 5 as a valid start offset here (which it is).