|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-03-10 10:34 UTC] jani@php.net
[2009-04-10 16:03 UTC] nlopess@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 17:00:01 2025 UTC |
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