|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-03-13 13:31 UTC] andrew dot coldham at home dot com
<!--
<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>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 12:00:01 2025 UTC |
Not a bug. I don't understand what you're trying to achieve here. $arkey = array("/TEST/e"); $arval = array("\$this->showX(\"$ar\")"); $outputstring = preg_replace($arkey,$arval,"First: TEST, done."); In your example, $arval evaluates to $this->showX("Array"), and that's what gets passed to preg_replace() which then call that method.