Tôi không phải là một guru C nhưng trong mã nguồn của hàm constructor giá trị dường như không được bảo quản ở tất cả:
/* {{{ proto DateInterval::__construct([string interval_spec])
Creates new DateInterval object.
*/
PHP_METHOD(DateInterval, __construct)
{
char *interval_string = NULL;
int interval_string_length;
php_interval_obj *diobj;
timelib_rel_time *reltime;
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &interval_string, &interval_string_length) == SUCCESS) {
if (date_interval_initialize(&reltime, interval_string, interval_string_length TSRMLS_CC) == SUCCESS) {
diobj = zend_object_store_get_object(getThis() TSRMLS_CC);
diobj->diff = reltime;
diobj->initialized = 1;
} else {
ZVAL_NULL(getThis());
}
}
zend_restore_error_handling(&error_handling TSRMLS_CC);
}
/* }}} */
Cả dường như làm date_interval_initialize()
chức năng:
static int date_interval_initialize(timelib_rel_time **rt, /*const*/ char *format, int format_length TSRMLS_DC)
{
timelib_time *b = NULL, *e = NULL;
timelib_rel_time *p = NULL;
int r = 0;
int retval = 0;
struct timelib_error_container *errors;
timelib_strtointerval(format, format_length, &b, &e, &p, &r, &errors);
if (errors->error_count > 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown or bad format (%s)", format);
retval = FAILURE;
} else {
if(p) {
*rt = p;
retval = SUCCESS;
} else {
if(b && e) {
timelib_update_ts(b, NULL);
timelib_update_ts(e, NULL);
*rt = timelib_diff(b, e);
retval = SUCCESS;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse interval (%s)", format);
retval = FAILURE;
}
}
}
timelib_error_container_dtor(errors);
return retval;
}
Nguồn
2013-03-06 15:50:37
Tôi không thích triển khai này. Nó đang lặp qua một đối tượng có thể có bất kỳ số lượng trường bổ sung nào trong tương lai ngoài "ngày" và nó đã có chúng trong PHP 5.4. Các lớp tĩnh cũng là một ý tưởng tồi. Và không có hàm như 'upper' trong PHP. –