Edit report at https://bugs.php.net/bug.php?id=64730&edit=1

 ID:                 64730
 Comment by:         ww dot galen at gmail dot com
 Reported by:        imbolk at gmail dot com
 Summary:            preg_replace_callback vs. preg_replace eval related
 Status:             Assigned
 Type:               Feature/Change Request
 Package:            Regexps related
 Operating System:   Mac OS X 10.8.3
 PHP Version:        5.5.0beta4
 Assigned To:        laruence
 Block user comment: N
 Private report:     N

 New Comment:

Accepting an array of callbacks can lead to unreconcilable ambiguities. For 
example:

    class A {
        function __toString() { ... }
        function __invoke($a) { ... }
        function foo($a) { ... }
    }
    function foo($a) { ... }
    
    $a = new A;
    preg_replace_callback([..., ...], [$a, 'foo'], $subject);

There are three different ways of interpreting the callback argument, all 
equally valid:

1. `(string)$a` and `foo(...)`
2. `$a(...)` and `foo(...)`
3. `$a->foo(...)`


Previous Comments:
------------------------------------------------------------------------
[2013-04-29 18:03:49] imbolk at gmail dot com

I think it would be better if prey_replace_callback function will accept array 
of 
callbacks as a 2nd argument.

------------------------------------------------------------------------
[2013-04-29 16:49:45] larue...@php.net

a simple patch attached, please also see my proposal: 
http://news.php.net/php.internals/67199

------------------------------------------------------------------------
[2013-04-29 16:31:42] imbolk at gmail dot com

Oops… sorry. My mistake. Test script is:

$repl = [
            '/(\d{2}|(?<!\d))([pm])(\d{2}|)([PMc])/e' => function($m) { return 
$this->_op($m[3], $m[4], rtrim($this->_op($m[1], $m[2]), ";"))'; },

            '/(\d{2}|)([MPmplrc])/e' => function ($m) { return 
$this->_op($m[1], 
$m[2]); },
        ];

$str = preg_replace_callback(array_keys($repl), array_values($repl), $str);

------------------------------------------------------------------------
[2013-04-29 16:30:36] larue...@php.net

The following patch has been added/updated:

Patch Name: sencode_argument.patch
Revision:   1367253036
URL:        
https://bugs.php.net/patch-display.php?bug=64730&patch=sencode_argument.patch&revision=1367253036

------------------------------------------------------------------------
[2013-04-29 15:52:38] larue...@php.net

or, add a third argument to callback, which is the "regex self" or the regex 
index?

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=64730


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64730&edit=1

Reply via email to