Bug #3820: preg_replace with /e function
| From: | andrew dot coldham at home dot com | Date: | Mon, 13 Mar 2000 18:31:20 +0000 |
| Subject: | Bug #3820: preg_replace with /e function | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-16757@lists.php.net to get a copy of this message | ||
From: andrew.coldham@home.com
Operating system: Linux
PHP version: 3.0 Latest CVS (13/03/2000)
PHP Bug Type: Misbehaving function
Bug description: preg_replace with /e function
<!--
<B>php4.0b4pl1</b><Br>
Using the /e parameter in the preg_replace function causes
$this->showX to misbehave. It can access member data arrays, such as var $ar; but has trouble
with objects passed in (arrays, classes):
"\$this->showX(\"$ar\")"
Thanks,
Andrew
-->
<?php
// Bug?
class myClass {
var $ar;
function myClass(){
}
function callX(){
$this->ar["one"] = "one";
$this->ar["two"] = "two";
$ar["one"] = 1;
$ar["two"] = 2;
$arkey = array("/TEST/e");
$arval = array("\$this->showX(\"$ar\")");
$outputstring = preg_replace($arkey,$arval,"First: TEST, done.");
echo $outputstring;
$outputstring =
preg_replace("/TEST/e","\$this->showX(\"$ar\")","TESTing 1 2
3");
echo $outputstring;
}
function showX($ar){
$str = $ar["one"];
$str2 = $this->ar["one"];
echo "String: [num:$str : word:$str2]";
}
}
$c = new myClass;
$c->callX();
?>
<p>I get the following output:
<p>
<pre>String: [num:A : word:one]String: [num:A : word:one]ing 1 2 3</pre>
<p>where I think it should be:
<pre>String: [num:1 : word:one]String: [num:A : word:one]ing 1 2 3</pre>