ID: 47586
Updated by: [email protected]
Reported By: didier dot peereboom at gmail dot com
Status: Open
-Bug Type: Reproducible crash
+Bug Type: PCRE related
Operating System: linux
PHP Version: 5.2.9
New Comment:
Note: Your script does not crash for me with PHP 5.2.9.
Previous Comments:
------------------------------------------------------------------------
[2009-03-06 12:17:39] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47586&edit=1