Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Improve ERROR.CONVENTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
cataphract committed Jun 2, 2013
1 parent e29647e commit d577260
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ERROR.CONVENTIONS
Expand Up @@ -81,3 +81,35 @@ ICU operates, where functions return immediately if an error is set.
Error resetting can be done with:
void intl_error_reset(NULL TSRMLS_DC); /* reset global error */
void intl_errors_reset(intl_error* err TSRMLS_DC ); /* reset global and object error */

In practice, intl_errors_reset() is not used because most classes have also
plain functions mapped to the same internal functions as their instance methods.
Fetching of the object is done with zend_parse_method_parameters() instead of
directly using getThis(). Therefore, no reference to object is obtained until
the arguments are fully parsed. Without a reference to the object, there's no
way to reset the object's internal error code. Instead, resetting of the
object's internal error code is done upon fetching the object from its zval.

Example:
U_CFUNC PHP_FUNCTION(breakiter_set_text)
{
/* ... variable declations ... */
BREAKITER_METHOD_INIT_VARS; /* macro also resets global error */
object = getThis();

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&text, &text_len) == FAILURE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"breakiter_set_text: bad arguments", 0 TSRMLS_CC);
RETURN_FALSE;
}

/* ... */

BREAKITER_METHOD_FETCH_OBJECT; /* macro also resets object's error */

/* ... */
}

Implementations of ::getErrorCode() and ::getErrorMessage() should not reset the
object's error code.

0 comments on commit d577260

Please sign in to comment.