php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28119 ereg_replace require string casting?
Submitted: 2004-04-23 09:33 UTC Modified: 2004-04-23 17:58 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: vb_user at yahoo dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.3.5 OS: Windows 2003
Private report: No CVE-ID: None
 [2004-04-23 09:33 UTC] vb_user at yahoo dot com
Description:
------------
When i pass in ereg_replace a variable like this:

ereg_replace($pattern, $variable, $string);

and $variable is holding an integer value, then $string will be replace with blank, not the value hold in $variable. This only happen in Windows installation not Linux as i have used this many times.

Doing the following will fix the problem:

ereg_replace($pattern, (string)$variable, $string);

But does that mean PHP is now no long type tolerant?

Reproduce code:
---------------
$variable = 13;
$pattern = 'test';
$string = 'this is a test';
ereg_replace($pattern, $variable, $string);

Expected result:
----------------
this is 13

Actual result:
--------------
this is

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-23 17:58 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

When you pass a non-string value as the 'replace' to 
ereg_replace() function it converts the argument to a 
number and then to the character represented by that 
number. 
Number 13 gets converted to the \r, with which the word 
test is replaced in your test. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC