php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41395 behaviour of substr_replace changed in php 5.2.2
Submitted: 2007-05-15 08:53 UTC Modified: 2007-07-29 23:33 UTC
From: daniel dot menard at bdsp dot tm dot fr Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.2 OS: windows 2003 server
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daniel dot menard at bdsp dot tm dot fr
New email:
PHP Version: OS:

 

 [2007-05-15 08:53 UTC] daniel dot menard at bdsp dot tm dot fr
Description:
------------
The behaviour of substr_replace seems to have changed in php 5.2.2 when the length parameter is specified and is greater than the actual length of the string to modify.

With php < 5.2.2, the string is extended, with php 5.2.2 substr_replace returns false.

I don't know if this is an intended change or not, but this change is not documented in the function description.

Just in case it matters: I'm using php 5.2.2 in cli mode with apache/2.2.4 on a windows 2003 server.

Note: perhaps it is related to http://bugs.php.net/bug.php?id=40754

Thanks !

Reproduce code:
---------------
<?php
    echo PHP_VERSION, ' : ';
    var_dump(substr_replace('012', 'ABCD', 0, 4));
?>

Expected result:
----------------
either the same result as in in previous php versions
or a note in the documentation stating that the behaviour has changed.

Actual result:
--------------
with PHP 5.2.2, I get:
5.2.2 : bool(false)

With older versions of php I get:
5.2.1 : string(4) "ABCD"
5.2.0 : string(4) "ABCD"
5.1.2 : string(4) "ABCD"
5.1.1 : string(4) "ABCD"


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-16 12:58 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2007-05-21 07:16 UTC] daniel dot menard at bdsp dot tm dot fr
I double-checked the manual :

"If length is given and is positive, it represents the length of the portion of string which is to be replaced. If it is negative, it represents the number of characters from the end of string at which to stop replacing. If it is not given, then it will default to strlen( string ); i.e. end the replacing at the end of string. Of course, if length is zero then this function will have the effect of inserting replacement into string at the given start offset."

I see nothing saying what happens if length is greater than the length of the string, neither I see anything stating that there were changes concerning this function in php 5.2.2...
 [2007-07-29 23:33 UTC] jani@php.net
See bug #42142 for further info.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 13 03:01:28 2024 UTC