php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68617 numeric interpretation of false
Submitted: 2014-12-17 16:47 UTC Modified: 2014-12-17 19:29 UTC
From: r dot putz at gmx dot de Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.5.19 OS: any
Private report: No CVE-ID: None
 [2014-12-17 16:47 UTC] r dot putz at gmx dot de
Description:
------------
---
From manual page: http://www.php.net/function.substr-replace
---

in substr_replace param start = false is interpreted as numeric position 0.

(interpreting 0 as false maybe ok, but the other way round?..)



Test script:
---------------
/* example replacing delemiter in a string */

$string = "foo1, foo2, foo3";
$string = substr_replace($string, ' and', strrpos($string, ','), 1);
echo $string;
/* output as expected: "foo1, foo2 and foo3"; */

/* no delemiter in string so should do nothing */
$string = "foo1";
$string = substr_replace($string, ' and', strrpos($string, ','), 1);
echo $string;
/* wrong output: " andoo1"; */


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-17 18:54 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-12-17 18:54 UTC] requinix@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

You need to do your own error checking. For all substr_replace() knows, using false/0 *is* what you want it to do.
 [2014-12-17 19:29 UTC] r dot putz at gmx dot de
sure do my own error checking!
mainly complaining about strange behaviour interpreting false as numeric in general (whereas vice versa it makes sense, even though not nice..;-)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 02:01:30 2024 UTC