Bug #69931 [Nab]: substr() behaviour change

From: Date: Thu, 25 Jun 2015 21:20:25 +0000
Subject: Bug #69931 [Nab]: substr() behaviour change
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193890@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69931&edit=1

 ID:                 69931
 Updated by:         yohgaki@php.net
 Reported by:        thekid@php.net
 Summary:            substr() behaviour change
 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:

I support this change.
However, this change may bite people. It should be clearly noted in UPGRADING.
A company that I know of was bitten by strtotime() return value change by PHP 5.1 and lost few
million dollars, for example.


Previous Comments:
------------------------------------------------------------------------
[2015-06-25 10:48:48] nikic@php.net

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).

------------------------------------------------------------------------
[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)

« previous php.bugs (#193890) next »