php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #5833 ereg_replace fails to use correct variable type
Submitted: 2000-07-28 13:06 UTC Modified: 2000-08-18 07:23 UTC
From: cveld at bigfoot dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0.1pl2 OS: win32
Private report: No CVE-ID: None
 [2000-07-28 13:06 UTC] cveld at bigfoot dot com
<?
// bug!!! try it out, the example does not print 3 but a weird box.

$num= 3;

$str= "%test%";

$str= ereg_replace("%test%", $num, $str);

echo $str;
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-28 14:10 UTC] waldschrott@php.net
actually, that?s not ereg?s fault, if you change
$num=3;
to
$num='3'; // a string

it?ll work

it?s maybe an (OS-specific?) autoconversion bug, the string should be converted to '3' but for any reason it is not
 [2000-07-28 14:15 UTC] waldschrott@php.net
that "box" is a ASCII character with value 3, the error
schould now be easily fixable
 [2000-07-28 14:18 UTC] waldschrott@php.net
every number(integer) is converted to chr(number)
 [2000-07-29 12:59 UTC] stas@php.net
Seems this is not error, this is by design. Anybody cares to explain why?
 [2000-07-29 20:50 UTC] rasmus@php.net
It was to make it easy to use special chars in both the pattern and replacement strings.  In hindsight it probably wasn't the right design choice, but changing it at this point would cause backward compatibility problems.
 [2000-07-29 21:26 UTC] cveld at bigfoot dot com
I don't exactly know how php solves its dynamic type casting, but it should be so that $i= 3; would succeed IS_LONG and not IS_STRING. Is it so difficult to add a IS_STRING check to the ereg-functions? php is just not the language to default to binary encoding...
 [2000-07-29 21:36 UTC] stas@php.net
This behaviour, being rather unusual, should be then documented.
 [2000-08-18 07:23 UTC] torben@php.net
There's now a note about this in ereg_replace().
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Jun 15 00:00:02 2026 UTC