|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71827 substr_replace bug when length type is string
Submitted: 2016-03-15 14:50 UTC Modified: 2016-03-31 16:12 UTC
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:1 (25.0%)
From: php-mailing-list at lool dot fr Assigned: krakjoe (profile)
Status: Closed Package: Strings related
PHP Version: 7.0.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php-mailing-list at lool dot fr
New email:
PHP Version: OS:


 [2016-03-15 14:50 UTC] php-mailing-list at lool dot fr
When running it under php 7, $line is unchanged and a message is emitted :
PHP Warning:  substr_replace(): 'from' and 'len' should be of same type - numerical or array  in test.php on line 3.

$len is not auto-casted in integer….  Btw the message is not very clear as it mentions from and len that are not within the doc.
(in my real source code, $len was extracted as string from a database).
When $len is an integer, the function works as expected.

Tested ok        on php 5.3.10
Tested Not ok on php 7.0.3

Best regards,

Test script:
test results on

$line  = str_repeat(' ',20); $value ='03'; $pos=0; $len='2';
$line = substr_replace($line,$value,$pos,$len);
echo "[$line]\n";

Expected result:
[03                  ]

Actual result:
Warning: substr_replace(): 'from' and 'len' should be of same type - numerical or array  in /in/svDrE on line 3
[                    ]


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-31 16:12 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2016-03-31 16:12 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

I accidentally tagged the wrong bug number in the commit ...
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 20:01:30 2024 UTC