From:             imbolk at gmail dot com
Operating system: Mac OS X 10.8.3
PHP version:      5.5.0beta4
Package:          Regexps related
Bug Type:         Feature/Change Request
Bug description:preg_replace_callback vs. preg_replace eval related

Description:
------------
In PHP 5.5 'e' key preg_replace is deprecated: 
https://wiki.php.net/rfc/remove_preg_replace_eval_modifier

But I don't know how to replace evaled preg_replace with
preg_replace_callback in 
some case.

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

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

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

Test script:
---------------
$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(array_keys($repl), array_values($repl), $str);

Expected result:
----------------
It works.

Actual result:
--------------
Warning: preg_replace_callback(): Requires argument 2, 'Array', to be a
valid 
callback in my.php on line 359

-- 
Edit bug report at https://bugs.php.net/bug.php?id=64730&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64730&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64730&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64730&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64730&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64730&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64730&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64730&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64730&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64730&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64730&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64730&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64730&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64730&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64730&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64730&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64730&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64730&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64730&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64730&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64730&r=mysqlcfg

Reply via email to