|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-03-14 17:53 UTC] jani@php.net
[2009-03-14 18:03 UTC] h dot reindl at thelounge dot net
[2009-03-14 19:18 UTC] mattwil@php.net
[2009-03-14 19:26 UTC] h dot reindl at thelounge dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 05:00:01 2025 UTC |
Description: ------------ If you use str_replace and the needle is not in the string there should be no call to the replacement-function. This can produce much overhead if the function is complex At the moment you must manually check if you call the replace with strpos - I think in many cases this will not happen and there is running much overhead-code without any need in existing applications Even if you know the problem it needs ugly php-code for get best performance - If the php-core makes this check all exististing applications can get better performance Reproduce code: --------------- <?php $str = 'Test [f1] Replace'; $str = str_replace('[f1]', f1(), $str); $str = str_replace('[f2]', f2(), $str); function f1() { echo 'F1<br />'; } function f2() { echo 'F2<br />'; } ?> Expected result: ---------------- Only f1() should be called Actual result: -------------- f1() AND f2() are called