php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51845 preg_replace_callback anonymous function issue
Submitted: 2010-05-17 18:30 UTC Modified: 2010-08-09 00:56 UTC
From: jerry at jmweb dot net Assigned: felipe (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.3.2 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: jerry at jmweb dot net
New email:
PHP Version: OS:

 

 [2010-05-17 18:30 UTC] jerry at jmweb dot net
Description:
------------
Using an anonymous function as argument #2 in preg_replace_callback issues the following warning:
preg_replace_callback() [function.preg-replace-callback]: Requires argument 2, '', to be a valid callback

This warning was not thrown previously using PHP 5.3.1

Test script:
---------------
echo preg_replace_callback('~-([a-z])~', function ($match) {
    return strtoupper($match[1]);
}, 'hello-world');

Expected result:
----------------
helloworld

Actual result:
--------------
hello-world + warning

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-19 15:12 UTC] mike@php.net
-Status: Open +Status: Feedback
 [2010-05-19 15:12 UTC] mike@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Works here.
 [2010-08-09 00:56 UTC] felipe@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-08-09 00:56 UTC] felipe@php.net
'helloWorld' is what you get on 5.3.3.

Thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Sep 19 21:00:02 2025 UTC