php 7 bug in substr_replace function

php.internals

Pascal KISSIAN

10 years ago
Hi everybody, I don't know if this is the right place to report bugs. please let me know for the next time. This is a small snippet that shows the wrong behaviour : <?php $line = str_repeat(' ',20); $value ='03'; $pos=0; $len='2'; $line = substr_replace($line,$value,$pos,$len); echo "[$line]\n"; ?> 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

Colin O'Dell

10 years ago
Hi Pascal, The bug tracker can be found here: https://bugs.php.net/ You might also want to include this link in your bug report - it shows the results of your test across multiple versions of PHP, thus confirming the behavior: https://3v4l.org/bPOK3 Cheers, Colin

Pascal KISSIAN

10 years ago
De : Colin O'Dell [mailto:colinodell@gmail.com] Envoyé : mardi 15 mars 2016 15:36 À : Pascal KISSIAN <php-mailing-list@lool.fr>; internals@lists.php.net Objet : Re: [PHP-DEV] php 7 bug in substr_replace function Hi Pascal, The bug tracker can be found here: https://bugs.php.net/ You might also want to include this link in your bug report - it shows the results of your test across multiple versions of PHP, thus confirming the behavior: https://3v4l.org/bPOK3 Cheers, Colin Thanks, Bug now submitted on bugs.php.net : https://bugs.php.net/bug.php?id=71827