Bug #69144 [NEW]: strtr not replacing with partly matching replace pairs
From: wouter at wouterj dot nl
Operating system:
PHP version: master-Git-2015-02-28 (snap)
Package: Strings related
Bug Type: Bug
Bug description:strtr not replacing with partly matching replace pairs
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
--
Edit bug report at https://bugs.php.net/bug.php?id=69144&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69144&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69144&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69144&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69144&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69144&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69144&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69144&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69144&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69144&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69144&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69144&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69144&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69144&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69144&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69144&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69144&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69144&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69144&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69144&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69144&r=mysqlcfg
Thread (2 messages)
- wouter at wouterj dot nl