php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47586 preg_replace_callback crashes on static method call that are NOT defined static
Submitted: 2009-03-06 12:17 UTC Modified: 2009-04-10 16:03 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: didier dot peereboom at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.9 OS: linux
Private report: No CVE-ID: None
 [2009-03-06 12:17 UTC] didier dot peereboom at gmail dot com
Description:
------------
preg_replace_callback can be passed a method, including static methods.

However if said function is not declared with the keyword static then it crashes hard. This is NOT the same as the behavior call_user_func which continues happily no matter what the function has been declared as.

Either call_user_func is wrong in working with incorrect code or preg_replace_callback is wrong in not working. The hard crash itself can hardly be intended behavior in either case.



Reproduce code:
---------------
<?php
class testing {
        function Main() {
                $this->ToBeCalledStatic('Regular');
                testing::ToBeCalledStatic('Static call');
                $var = "Method passed as array";
                $var1 = "Method passed as static string";
                $func = array('testing','ToBeCalledStatic');
                $func1 = 'testing::ToBeCalledStatic';
                call_user_func($func, $var);
                preg_replace_callback('/.*/', $func , $var);
                call_user_func($func1, $var1);
                preg_replace_callback('/.*/', $func1 , $var1);
        }
        function ToBeCalledStatic($msg) {
                echo "Been called with [{$msg}]\n";
        }
}
$tmp1 = new testing();
$tmp1->Main();
?>

Expected result:
----------------
Either an error message in both cases that the function should be declared static OR to work in both cases.

Not to work for call_user_func and fail for preg_replace_callback.

Perhaps with the update to the static notiation option preg_replace_callback was overlooked?


Actual result:
--------------
Been called with [Regular]
Been called with [Static call]
Been called with [Method passed as array]
Been called with [Array]
Been called with [Array]

Warning: call_user_func(testing::ToBeCalledStatic): First argument is expected to be a valid callback in /home/didier/test.php on line 12

Call Stack:
    0.0002     115008   1. {main}() /home/didier/test.php:0
    0.0002     115384   2. testing->Main() /home/didier/test.php:20
    0.0004     118432   3. call_user_func() /home/didier/test.php:12

Dump $_SERVER
Dump $_GET
Dump $_POST
Dump $_COOKIE
Dump $_FILES
Dump $_ENV
Dump $_SESSION
Dump $_REQUEST

Warning: preg_replace_callback(): Requires argument 2, 'testing::ToBeCalledStatic', to be a valid callback in /home/didier/test.php on line 13

Call Stack:
    0.0002     115008   1. {main}() /home/didier/test.php:0
    0.0002     115384   2. testing->Main() /home/didier/test.php:20
    0.0005     119104   3. preg_replace_callback() /home/didier/test.php:13


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-10 10:34 UTC] jani@php.net
Note: Your script does not crash for me with PHP 5.2.9.

 [2009-04-10 16:03 UTC] nlopess@php.net
works here with 5.3-cvs.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 06:01:28 2024 UTC