summaryrefslogtreecommitdiff
path: root/ext/json/json.c
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2012-06-28 20:18:19 +0200
committerNikita Popov <nikic@php.net>2012-06-28 20:18:19 +0200
commit405ebfcd182a39f0960ff7d7055d49053d3e0316 (patch)
treebb05d983ab5a9301ae97838d8d6c8c002e8200e7 /ext/json/json.c
parent2996eeeed094f66d57d79552d642129d60937c6d (diff)
parent974324676b2436f159f42d9241c569f813471684 (diff)
downloadphp-git-405ebfcd182a39f0960ff7d7055d49053d3e0316.tar.gz
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: Add json_last_error_msg() function
Diffstat (limited to 'ext/json/json.c')
-rw-r--r--ext/json/json.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index 5ea307020a..b467079610 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -35,6 +35,7 @@ static PHP_MINFO_FUNCTION(json);
static PHP_FUNCTION(json_encode);
static PHP_FUNCTION(json_decode);
static PHP_FUNCTION(json_last_error);
+static PHP_FUNCTION(json_last_error_msg);
static const char digits[] = "0123456789abcdef";
@@ -55,8 +56,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_json_decode, 0, 0, 1)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_json_last_error, 0, 0, 0)
- ZEND_ARG_INFO(0, as_string)
+ZEND_BEGIN_ARG_INFO(arginfo_json_last_error, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_json_last_error_msg, 0)
ZEND_END_ARG_INFO()
/* }}} */
@@ -65,6 +68,7 @@ static const zend_function_entry json_functions[] = {
PHP_FE(json_encode, arginfo_json_encode)
PHP_FE(json_decode, arginfo_json_decode)
PHP_FE(json_last_error, arginfo_json_last_error)
+ PHP_FE(json_last_error_msg, arginfo_json_last_error_msg)
PHP_FE_END
};
/* }}} */
@@ -746,21 +750,25 @@ static PHP_FUNCTION(json_decode)
/* }}} */
/* {{{ proto int json_last_error()
- Returns the error code of the last json_decode(). */
+ Returns the error code of the last json_encode() or json_decode() call. */
static PHP_FUNCTION(json_last_error)
{
- zend_bool as_string = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &as_string) == FAILURE) {
+ if (zend_parse_parameters_none() == FAILURE) {
return;
}
- /* return error code (JSON_ERROR_* constants) */
- if (!as_string) {
- RETURN_LONG(JSON_G(error_code));
+ RETURN_LONG(JSON_G(error_code));
+}
+/* }}} */
+
+/* {{{ proto string json_last_error_msg()
+ Returns the error string of the last json_encode() or json_decode() call. */
+static PHP_FUNCTION(json_last_error_msg)
+{
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
}
- /* return error message (for debugging purposes) */
switch(JSON_G(error_code)) {
case PHP_JSON_ERROR_NONE:
RETURN_STRING("No error", 1);
@@ -783,6 +791,7 @@ static PHP_FUNCTION(json_last_error)
default:
RETURN_STRING("Unknown error", 1);
}
+
}
/* }}} */