# Bug #24281

- Thread: https://externals.io/message/2532
- Original archive: https://news-web.php.net/php.internals/2532
- Started by Marco Tabini on 2003-06-22T13:07:15+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #2532 — Marco Tabini — 2003-06-22T13:07:15+00:00

URL: https://externals.io/message/2532#2532

I stumbled upon bug #24281 while running a few test on the current HEAD
for PHP5--it seems to me that it should be sufficient to change a single
line of code to make `str_replace()` work as expected, but I'm not
familiar enough with the internals to know whether my fix is good or
not...so, here it is. It seems to work for my test case, and for the
test case reported in the bug.

Cheers,


Marco

Index: string.c
===================================================================
RCS file: /repository/php4/ext/standard/string.c,v
retrieving revision 1.391
diff -u -r1.391 string.c
--- string.c    20 Jun 2003 15:41:43 -0000      1.391
+++ string.c    22 Jun 2003 13:06:51 -0000
@@ -3194,7 +3194,7 @@
                php_str_replace_in_subject(*search, *replace, subject, return_value, case_sensitivity, (argc > 3) ? &count : NULL);
        }
        if (argc > 3) {
-               Z_LVAL_PP(zcount) = count;
+               ZVAL_LONG(*zcount, count);
        }
 }
 /* }}} */

---

## #2534 — Marco Tabini — 2003-06-22T13:29:28+00:00

URL: https://externals.io/message/2532#2534 · In reply to: #2532

Take two (this time hopefully clearing the variable before resetting it):

Index: string.c
===================================================================
RCS file: /repository/php4/ext/standard/string.c,v
retrieving revision 1.391
diff -u -r1.391 string.c
--- string.c    20 Jun 2003 15:41:43 -0000      1.391
+++ string.c    22 Jun 2003 13:29:22 -0000
@@ -3194,7 +3194,8 @@
                php_str_replace_in_subject(*search, *replace, subject, return_value, case_sensitivity, (argc > 3) ? &count : NULL);
        }
        if (argc > 3) {
-               Z_LVAL_PP(zcount) = count;
+               zval_dtor(*zcount);
+               ZVAL_LONG(*zcount, count);
        }
 }
 /* }}} */
