From:             didier dot peereboom at gmail dot com
Operating system: linux
PHP version:      5.2.9
PHP Bug Type:     Reproducible crash
Bug description:  preg_replace_callback crashes on static method call that are 
NOT defined static

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 bug report at http://bugs.php.net/?id=47586&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=47586&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=47586&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=47586&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=47586&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=47586&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=47586&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=47586&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=47586&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=47586&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=47586&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=47586&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=47586&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=47586&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=47586&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=47586&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=47586&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=47586&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=47586&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=47586&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=47586&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=47586&r=mysqlcfg

Reply via email to