php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3820 preg_replace with /e function
Submitted: 2000-03-13 13:31 UTC Modified: 2000-03-21 11:19 UTC
From: andrew dot coldham at home dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0 Latest CVS (13/03/2000) OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrew dot coldham at home dot com
New email:
PHP Version: OS:

 

 [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>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-03-21 11:19 UTC] andrei at cvs dot php dot net
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.

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 10:01:33 2025 UTC