php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69144 strtr not replacing with partly matching replace pairs
Submitted: 2015-02-28 11:15 UTC Modified: -
From: wouter at wouterj dot nl Assigned:
Status: Closed Package: Strings related
PHP Version: master-Git-2015-02-28 (snap) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wouter at wouterj dot nl
New email:
PHP Version: OS:

 

 [2015-02-28 11:15 UTC] wouter at wouterj dot nl
Description:
------------
Testing against the latest PHP 7 version, there seem to be a bug with the strtr function. As soon as you use replace pairs (the 2 arguments usage), the function won't replace anything if the replace pairs are matching eachother (e.g. in the test script "foobar" matches both "fo" and "bar").

From some tests[1], it seems like this bug has been introduced between January 1st and February 1st in the PHP 7 branch.

 [1] http://3v4l.org/FTV2L

Test script:
---------------
<?php
$tests = array('bar' => '', 'foo' => 'o', 'foobar' => '', 'hello' => 'hello');

foreach ($tests as $input => $expected) {
    if ($expected !== ($actual = strtr($input, array("fo" => "", "foobar" => "", "bar" => "")))) {
        echo "KO `$input` became `$actual` instead of `$expected`\n";
    } else {
        echo "OK `$input` became `$expected`\n";
    }
}
?>

Expected result:
----------------
OK `bar` became ``
OK `foo` became `o`
OK `foobar` became ``
OK `hello` became `hello`

Actual result:
--------------
KO `bar` became `bar` instead of ``
KO `foo` became `foo` instead of `o`
KO `foobar` became `foobar` instead of ``
OK `hello` became `hello`

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-28 14:38 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=54e2020ee3e6142a86db03f1a9d47bc763334dbb
Log: Fixed bug #69144 (strtr not replacing with partly matching replace pairs)
 [2015-02-28 14:38 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:39 UTC] davey@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=54e2020ee3e6142a86db03f1a9d47bc763334dbb
Log: Fixed bug #69144 (strtr not replacing with partly matching replace pairs)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC