|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-02-04 14:59 UTC] iliaa@php.net
[2009-02-05 12:17 UTC] janne dot salo at exove dot fi
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 12:00:01 2025 UTC |
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))