From:             vl409 at yandex dot ru
Operating system: linux-2.4.25,freebsd 4.10
PHP version:      4.3.10
PHP Bug Type:     *General Issues
Bug description:  set_error_handler() object argument passed by value,not 
reference

Description:
------------
Possibly,it`s a duplicate bug of
 Bug #25128     set_error_handler not sending reference
http://bugs.php.net/bug.php?id=25128&edit=2

I tried to write my own class for handling errors in php and
found that if i call set_error_handler with argument, being
object(&$this), it is passed by value, not by reference.

This is strange, because function set_error_handler is
declared same as call_user_func, but behaves differently.

as defined in manual:
mixed call_user_func ( callback function...)
mixed set_error_handler ( callback error_handler...)

I tested example on FreeBSD 4.1/PHP 4.3.10 and Linux 2.4.25/PHP 4.3.5

Code,demonstrating this, provided below.

P.S. If it`s a duplication, then you can mean this report as BUG IN
DOCUMENTATION! I found that i wanted to do almost the same as man in Bug
#25128, but due to lack of documentation, spent a lot of time for
nothing...


Reproduce code:
---------------
<?php
class error_handler
{       var $error_count;
        function error_handler(){
                $this->error_count=0;
                set_error_handler(array(&$this,'handler'));
                echo "<b>New error handler registered!</b><br>";
        }
        function handler()
        {
                echo "Cought an error! increasing counter!<br>";
                $this->error_count++;}
        function show(){
                echo "This object handled ".$this->error_count." errors<br>";
        }
}

$x=new error_handler;

$x->show();

trigger_error("Ooops!",E_USER_ERROR);
$x->show();
trigger_error("Ooops!",E_USER_ERROR);
$x->show();
echo "<b>called by call_user_func:</b><br>";
call_user_func(array(&$x, "handler"));
$x->show();
echo "<b>called manually</b><br>";
$x->handler();
$x->show();

?>

Expected result:
----------------
New error handler registered!
This object handled 0 errors
Cought an error! increasing counter!
This object handled 1 errors
Cought an error! increasing counter!
This object handled 2 errors
called by call_user_func:
Cought an error! increasing counter!
This object handled 3 errors
called manually
Cought an error! increasing counter!
This object handled 4 errors

Actual result:
--------------
New error handler registered!
This object handled 0 errors
Cought an error! increasing counter!
This object handled 0 errors
Cought an error! increasing counter!
This object handled 0 errors
called by call_user_func:
Cought an error! increasing counter!
This object handled 1 errors
called manually
Cought an error! increasing counter!
This object handled 2 errors

-- 
Edit bug report at http://bugs.php.net/?id=31798&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31798&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31798&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31798&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31798&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31798&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31798&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31798&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31798&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31798&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31798&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31798&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31798&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31798&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31798&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31798&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31798&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31798&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31798&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=31798&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31798&r=mysqlcfg

Reply via email to