]> granicus.if.org Git - php/commitdiff
Improve ERROR.CONVENTIONS
authorGustavo Lopes <glopes@nebm.ist.utl.pt>
Tue, 29 Jan 2013 15:17:55 +0000 (16:17 +0100)
committerGustavo Lopes <glopes@nebm.ist.utl.pt>
Tue, 29 Jan 2013 18:06:14 +0000 (19:06 +0100)
ext/intl/ERROR.CONVENTIONS

index 54f30edcaa9c14ef8ad82395cc8a0009cbe8ac2d..6f9079c56d04c53fa2984fc68c915db7260022ea 100644 (file)
@@ -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.