php.net |  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
Votes:4
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
 [2016-03-15 14:50 UTC] php-mailing-list at lool dot fr
Description:
------------
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,
Pascal KISSIAN


Test script:
---------------
test results on https://3v4l.org/svDrE


<?php
$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
[                    ]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-31 16:12 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2016-03-31 16:12 UTC] krakjoe@php.net
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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
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: Tue Dec 03 17:01:29 2024 UTC