php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11085 preg_replace_callback and class methods
Submitted: 2001-05-24 08:38 UTC Modified: 2001-05-24 09:25 UTC
From: bilo at mit dot it Assigned:
Status: Closed Package: PCRE related
PHP Version: 4.0.5 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: bilo at mit dot it
New email:
PHP Version: OS:

 

 [2001-05-24 08:38 UTC] bilo at mit dot it
I was using preg_replace with the '/F' parameter, and it
was working perfectly till v4.0.4pl1. Now it has been
substituted by preg_replace_callback.

Does preg_replace_callback work with class method as a callback function, too? If it does, how should it be
written?

I'm asking this because in each of these cases:

preg_replace_callback(/{([A-Z_][A-Z0-9_]*)}/i', $this->callmeback, $text);
preg_replace_callback(/{([A-Z_][A-Z0-9_]*)}/i', "\$this->callmeback", $text);
preg_replace_callback(/{([A-Z_][A-Z0-9_]*)}/i', '$this->callmeback', $text);

I get a warning:

preg_replace_callback() requires argument 2, [...],
to be a valid callback

More: there is another drawback. With preg_replace + '/F' parameter I could also specify additional parameters in the command line. Now I can't.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-24 09:25 UTC] mfischer@php.net
Method callbacks are performed with the syntax array( $object, 'method'); in your case you want to write 

preg_replace_callback( '/{([A-Z_][A-Z0-9_]*)}/i', array( &$this, 'callmeback');, $text);

Btw, you missed the ' after callback( ...

- Markus
 [2001-05-24 09:25 UTC] mfischer@php.net
Forget the ';' after 'callmeback') ...

- Markus
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Oct 15 17:01:25 2018 UTC