ID:               47298
 Updated by:       [email protected]
 Reported By:      janne dot salo at exove dot fi
-Status:           Open
+Status:           Bogus
 Bug Type:         Strings related
 Operating System: CentOS 5.2
 PHP Version:      5.2.8
 New Comment:

php 5.1.2 returns 12, so there is no BC break here.


Previous Comments:
------------------------------------------------------------------------

[2009-02-04 08:40:38] janne dot salo at exove dot fi

Description:
------------
When substr is given a negative value as $start AND the absolute value
of $start is greater than the length of the string, something unexpected
occurs: $start seems to be considered equal to 0 in this case.

The documentation states: "If string is less than or equal to start
characters long, FALSE will be returned". Strict intepretation would be
that if $start is negative, FALSE will never be returned since a
negative start can never be greater than the length of the string.
However, what you would expect (and what you get in versions older than
5.2.8) is that if the ABSOLUTE value of start is greater than the length
of the string, FALSE will be returned. 

Reproduce code:
---------------
substr("1234567", -9, 2);

Expected result:
----------------
The above call returns FALSE in previous PHP versions (tested with
5.2.2 in MacOS X and 5.2.6 in Fedora 8).

Actual result:
--------------
'12'. (Which corresponds to call substr("1234567", 0, 2))


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47298&edit=1

Reply via email to