Bug #74935 [NEW]: mb_str*pos functions do not take into consideration mb_internal_encoding

From: Date: Mon, 17 Jul 2017 08:50:41 +0000
Subject: Bug #74935 [NEW]: mb_str*pos functions do not take into consideration mb_internal_encoding
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210080@lists.php.net to get a copy of this message
From: andxfiles at gmail dot com Operating system: All PHP version: Irrelevant Package: mbstring related Bug Type: Bug Bug description:mb_str*pos functions do not take into consideration mb_internal_encoding Description: ------------ when calling mb_str*pos (stripos, strrpos etc.) functions using mb_internal_encoding before their call instead of passing the encoding as a parameter, those functions do not use the encoding provided, thus being way slower. As one can see in the actual results below, when using mb_internal_encoding, all functions become way faster except for mb_stripos. Test script: --------------- <?php $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_strlen("fdsfdssdfoifjosdifjosdifjosdij:ά", "UTF-8"); } $finishtime = microtime(true); echo "mb_strlen with parameter UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_stripos("fdsfdssdfoifjosdifjosdifjosdij:ά", "α", 0, "UTF-8"); } $finishtime = microtime(true); echo "mb_stripos with parameter UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_substr("fdsfdssdfoifjosdifjosdifjosdij:ά", $i, 1, "UTF-8"); } $finishtime = microtime(true); echo "mb_substr with parameter UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; mb_internal_encoding("UTF-8"); $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_strlen("fdsfdssdfoifjosdifjosdifjosdij:ά"); } $finishtime = microtime(true); echo "mb_strlen with mb_internal_encoding UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_stripos("fdsfdssdfoifjosdifjosdifjosdij:ά", "α", 0); } $finishtime = microtime(true); echo "mb_stripos with mb_internal_encoding UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_substr("fdsfdssdfoifjosdifjosdifjosdij:ά", $i, 1); } $finishtime = microtime(true); echo "mb_substr with mb_internal_encoding UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; ?> Actual result: -------------- mb_strlen with parameter UTF8: 103.7 milliseconds mb_stripos with parameter UTF8: 1450.7 milliseconds mb_substr with parameter UTF8: 81.6 milliseconds mb_strlen with mb_internal_encoding UTF8: 39.2 milliseconds mb_stripos with mb_internal_encoding UTF8: 1435.3 milliseconds mb_substr with mb_internal_encoding UTF8: 48.5 milliseconds -- Edit bug report at https://bugs.php.net/bug.php?id=74935&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74935&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74935&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74935&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74935&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74935&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74935&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74935&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74935&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74935&r=support Expected behavior: https://bugs.php.net/fix.php?id=74935&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74935&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74935&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74935&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74935&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74935&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74935&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74935&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74935&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74935&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74935&r=mysqlcfg

« previous php.bugs (#210080) next »