php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48269 Unexpected return in substr function with negative start parameter
Submitted: 2009-05-13 20:47 UTC Modified: 2009-05-13 21:32 UTC
From: relo dot san at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.9 OS: CentOS 5
Private report: No CVE-ID: None
 [2009-05-13 20:47 UTC] relo dot san at gmail dot com
Description:
------------
From manual:
"If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string). If string is less than or equal to start characters long, FALSE will be returned."

This bug detected in PHP versions >= 5.2.8

Results on different versions and OS:
PHP Version 5.2.5, Windows and linux: boolean: false
PHP Version 5.2.8, CentOS: string(1) "1"
PHP 5.2.8 (cli) (built: Feb  5 2009 21:21:13), MacOS: string(1) "1"
PHP Version 5.2.9, CentOS: string(1) "1"

Maby is mistake in manual and substr do not accept negative start param if string length less than start?

Reproduce code:
---------------
var_dump( substr( '1', -2, 1 ) );

Expected result:
----------------
boolean: false

Actual result:
--------------
string(1) "1"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-13 21:32 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #47298
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 08:01:31 2025 UTC