PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_AJAX » Bug #8444

Handle PEAR_Errors returned from proxied object methods as errors

Details

Request #8444Handle PEAR_Errors returned from proxied object methods as errors
Submitted2006-08-15 10:36 UTC
Fromkoto at webworkers dot pl
Assignedauroraeosrose
StatusClosed
PackageHTML_AJAX
PHP Version5.1.0
OSwin
Roadmaps0.5.1

Comments

[2006-08-15 10:36 UTC] koto at webworkers dot pl

Description:
------------
Returning PEAR_Error object from proxied PHP object method returns message:

PHP Fatal error: Maximum function nesting level of '100' reached, aborting! in c:\php\PEAR\HTML\AJAX\JSON.php on line 241 (when using Xdebug extension - without it it would probably hang trying to convert the PEAR_Error object using the json serializer).

I think as PEAR_Error class is solely used to represent various errors in PHP applications built upon PEAR packages that there should be an option in HTML_AJAX to represent this class as any other error.

Appropriate working patch has already been submitted by Oliver Kuhl in mailing list:

--- AJAX.php.orig 2006-04-27 07:14:00.000000000 +0200
+++ AJAX.php 2006-04-27 07:41:16.000000000 +0200
@@ -430,6 +430,16 @@
if(is_object($response) && is_a($response, 'HTML_AJAX_Response')) {
$output = $response->getPayload();
$content = $response->getContentType();
+ } elseif(is_a($response, 'PEAR_Error')) {
+ $serializer = $this->_getSerializer($this->serializer);
+ $output = $serializer->serialize(array(
+ 'message' => $response->getMessage(),
+ 'userinfo' => $response->getUserInfo(),
+ 'code' => $response->getCode(),
+ 'mode' => $response->getMode()
+ )
+ );
+ $content = $this->contentTypeMap['Error'];
} else {
$serializer = $this->_getSerializer($this->serializer);
$output = $serializer->serialize($response);

Test script:
---------------
server.php
====
registerClass(new errortest,'errortest',array('geterror'));
$server->handleRequest();
?>

index.php
======

var callbacks = {
geterror : function(result) {
document.getElementById('result').innerHTML = result;
}
}

var remote = new errortest(callbacks);

<a href="#" onclick="remote.geterror(); return false;">show error</a>
</body>
</html>

Expected result:
----------------
Error-handling takes place as it is for 'regular' PHP errors

Actual result:
--------------
After a few seconds processing the request, following message is displayed in result div:

Fatal error: Maximum function nesting level of '100' reached, aborting! in c:\php\PEAR\HTML\AJAX\JSON.php on line 432

with the debug backtrace.