php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17264 Cannot call a method of the local class from preg_replace with /e option.
Submitted: 2002-05-15 22:15 UTC Modified: 2002-06-01 10:18 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sal at stodge dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.2.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sal at stodge dot org
New email:
PHP Version: OS:

 

 [2002-05-15 22:15 UTC] sal at stodge dot org
If you use preg_replace with the /e option from within a class you may want to call a method of the current class to perform the lookup. Intuativly a user might expect this code to work:

$whatever=preg_replace( $pattern,"$this->whatever('\\1')", $value );

That 2nd parameter is being evaluated outside the current class... In this context "$this" has no meaning outside the object,  So a method like "$this->whatever{foo)" can never be evaluated directly by this command.

The function works fine if you use it according to the instructions - that is you provide it with a globally available function it will work perfectly.

To check version & config of the my offending server:
http://sharesite.stodge.org/test.php

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-01 10:18 UTC] mfischer@php.net
You need to escape the '$', e.g.:

$whatever = preg_replace( $pattern,"\$this->whatever('\\1')", $value );
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 06:03:33 2021 UTC