PEAR::setErrorHandling in classes
| From: | Rich Payne | Date: | Tue, 26 Feb 2002 23:18:35 +0000 |
| Subject: | PEAR::setErrorHandling in classes | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-4886@lists.php.net to get a copy of this message | ||
I sent this to pear-general a few days and didn't get a response...hoping
someone here can help me.
I'm in the process of converting some code I wrote to use PEAR DB instead
of direct mysql access and have come accross something I don't understand.
I've been reading through Tomas V.V.Cox's intro to PEAR DB (it's been very
helpful BTW) and in there he has:
// You can also use an object as pear error handler so:
// setErrorHandling(PEAR_ERROR_CALLBACK, array($object,'method_name');
OK, so I used that and it never calls the function, if I misspell the
function name then PHP complains about the function not existing, but if
they match it never seem to get called. So, some example code:
Simple functional example, works great:
<?php
include_once 'DB.php';
$db_conn_data = array(
'phptype' => "mysql",
'hostspec' => "localhost",
'database' => "test",
'username' => "root",
'password' => " "
);
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_db_error');
$link = DB::connect($db_conn_data);
function handle_db_error (&$obj) {
echo "Test:: ".$obj->getMessage()."\n";
}
?>
Class example, fails:
<?php
include_once 'DB.php';
class test {
function test() {
$db_conn_data = array(
'phptype' => "mysql",
'hostspec' => "localhost",
'database' => "test",
'username' => "root",
'password' => " "
);
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this,'handle_db_error'));
$link = DB::connect($db_conn_data);
//var_dump($link);
}
function handle_db_error (&$obj) {
echo "Test:: ".$obj->getMessage();
}
}
?>
I'm just using another script to create an object of type test. Again, the
handle_db_error function never actually seems to get called.
Any help would be much appreciated.
thanks,
--rdp
--
Rich Payne
http://talisman.mv.com