Bug #69931 [Asn->Nab]: substr() behaviour change
Edit report at https://bugs.php.net/bug.php?id=69931&edit=1
ID: 69931
Updated by: nikic@php.net
Reported by: thekid@php.net
Summary: substr() behaviour change
-Status: Assigned
+Status: Not a bug
Type: Bug
Package: Strings related
Operating System: Ubuntu
PHP Version: 7.0Git-2015-06-25 (Git)
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
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).
Previous Comments:
------------------------------------------------------------------------
[2015-06-25 08:48:59] thekid@php.net
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.
------------------------------------------------------------------------
[2015-06-25 08:44:51] 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:
--------------
""
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69931&edit=1
Thread (4 messages)