summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/json.c30
-rw-r--r--ext/json/json.stub.php16
-rw-r--r--ext/json/json_arginfo.h23
-rw-r--r--ext/json/json_encoder.c2
-rw-r--r--ext/json/json_parser.y6
-rw-r--r--ext/json/json_scanner.re2
-rw-r--r--ext/json/php_json.h2
-rw-r--r--ext/json/php_json_encoder.h2
-rw-r--r--ext/json/php_json_parser.h2
-rw-r--r--ext/json/php_json_scanner.h2
-rw-r--r--ext/json/tests/001.phpt3
-rw-r--r--ext/json/tests/json_decode_error.phpt17
-rw-r--r--ext/json/tests/json_last_error_error.phpt17
-rw-r--r--ext/json/tests/json_last_error_msg_error.phpt15
14 files changed, 57 insertions, 82 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index 8474642266..5db3621b32 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
@@ -29,6 +27,7 @@
#include "php_json.h"
#include "php_json_encoder.h"
#include "php_json_parser.h"
+#include "json_arginfo.h"
#include <zend_exceptions.h>
static PHP_MINFO_FUNCTION(json);
@@ -42,27 +41,6 @@ PHP_JSON_API zend_class_entry *php_json_exception_ce;
PHP_JSON_API ZEND_DECLARE_MODULE_GLOBALS(json)
-/* {{{ arginfo */
-ZEND_BEGIN_ARG_INFO_EX(arginfo_json_encode, 0, 0, 1)
- ZEND_ARG_INFO(0, value)
- ZEND_ARG_INFO(0, options)
- ZEND_ARG_INFO(0, depth)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_json_decode, 0, 0, 1)
- ZEND_ARG_INFO(0, json)
- ZEND_ARG_INFO(0, assoc)
- ZEND_ARG_INFO(0, depth)
- ZEND_ARG_INFO(0, options)
-ZEND_END_ARG_INFO()
-
-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()
-/* }}} */
-
/* {{{ json_functions[] */
static const zend_function_entry json_functions[] = {
PHP_FE(json_encode, arginfo_json_encode)
@@ -74,12 +52,8 @@ static const zend_function_entry json_functions[] = {
/* }}} */
/* {{{ JsonSerializable methods */
-ZEND_BEGIN_ARG_INFO(json_serialize_arginfo, 0)
- /* No arguments */
-ZEND_END_ARG_INFO();
-
static const zend_function_entry json_serializable_interface[] = {
- PHP_ABSTRACT_ME(JsonSerializable, jsonSerialize, json_serialize_arginfo)
+ PHP_ABSTRACT_ME(JsonSerializable, jsonSerialize, arginfo_class_JsonSerializable_jsonSerialize)
PHP_FE_END
};
/* }}} */
diff --git a/ext/json/json.stub.php b/ext/json/json.stub.php
new file mode 100644
index 0000000000..6b00648461
--- /dev/null
+++ b/ext/json/json.stub.php
@@ -0,0 +1,16 @@
+<?php
+
+/** @return string|false */
+function json_encode($value, int $options = 0, int $depth = 512) {}
+
+/** @return mixed */
+function json_decode(string $json, ?bool $assoc = null, int $depth = 512, int $options = 0) {}
+
+function json_last_error(): int {}
+
+function json_last_error_msg(): string {}
+
+interface JsonSerializable
+{
+ public function jsonSerialize();
+}
diff --git a/ext/json/json_arginfo.h b/ext/json/json_arginfo.h
new file mode 100644
index 0000000000..b717716790
--- /dev/null
+++ b/ext/json/json_arginfo.h
@@ -0,0 +1,23 @@
+/* This is a generated file, edit the .stub.php file instead. */
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_json_encode, 0, 0, 1)
+ ZEND_ARG_INFO(0, value)
+ ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO(0, depth, IS_LONG, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_json_decode, 0, 0, 1)
+ ZEND_ARG_TYPE_INFO(0, json, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, assoc, _IS_BOOL, 1)
+ ZEND_ARG_TYPE_INFO(0, depth, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_json_last_error, 0, 0, IS_LONG, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_json_last_error_msg, 0, 0, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_JsonSerializable_jsonSerialize, 0, 0, 0)
+ZEND_END_ARG_INFO()
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index c0fcbe3282..d08a466643 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
diff --git a/ext/json/json_parser.y b/ext/json/json_parser.y
index aec9b225b8..ec5e4e81cf 100644
--- a/ext/json/json_parser.y
+++ b/ext/json/json_parser.y
@@ -1,8 +1,6 @@
%code top {
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
@@ -255,7 +253,6 @@ static int php_json_parser_object_update(php_json_parser *parser, zval *object,
if (Z_TYPE_P(object) == IS_ARRAY) {
zend_symtable_update(Z_ARRVAL_P(object), key, zvalue);
} else {
- zval zkey;
if (ZSTR_LEN(key) > 0 && ZSTR_VAL(key)[0] == '\0') {
parser->scanner.errcode = PHP_JSON_ERROR_INVALID_PROPERTY_NAME;
zend_string_release_ex(key, 0);
@@ -263,8 +260,7 @@ static int php_json_parser_object_update(php_json_parser *parser, zval *object,
zval_ptr_dtor_nogc(object);
return FAILURE;
}
- ZVAL_NEW_STR(&zkey, key);
- zend_std_write_property(object, &zkey, zvalue, NULL);
+ zend_std_write_property(Z_OBJ_P(object), key, zvalue, NULL);
Z_TRY_DELREF_P(zvalue);
}
zend_string_release_ex(key, 0);
diff --git a/ext/json/json_scanner.re b/ext/json/json_scanner.re
index a64d09bfc3..5b571e6dd2 100644
--- a/ext/json/json_scanner.re
+++ b/ext/json/json_scanner.re
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
diff --git a/ext/json/php_json.h b/ext/json/php_json.h
index 99afe8dd2d..4fc7ded7d4 100644
--- a/ext/json/php_json.h
+++ b/ext/json/php_json.h
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
diff --git a/ext/json/php_json_encoder.h b/ext/json/php_json_encoder.h
index e8266bfd06..8d9825b4fb 100644
--- a/ext/json/php_json_encoder.h
+++ b/ext/json/php_json_encoder.h
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
diff --git a/ext/json/php_json_parser.h b/ext/json/php_json_parser.h
index 8b6393d100..05f7a061c6 100644
--- a/ext/json/php_json_parser.h
+++ b/ext/json/php_json_parser.h
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
diff --git a/ext/json/php_json_scanner.h b/ext/json/php_json_scanner.h
index 7a9356146c..7a2d841703 100644
--- a/ext/json/php_json_scanner.h
+++ b/ext/json/php_json_scanner.h
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
diff --git a/ext/json/tests/001.phpt b/ext/json/tests/001.phpt
index e908b44349..63a303998a 100644
--- a/ext/json/tests/001.phpt
+++ b/ext/json/tests/001.phpt
@@ -5,7 +5,6 @@ json_decode() tests
--FILE--
<?php
-var_dump(json_decode());
var_dump(json_decode(""));
var_dump(json_decode("", 1));
var_dump(json_decode("", 0));
@@ -26,8 +25,6 @@ var_dump(json_decode('{ "": "": "" } }'));
?>
===DONE===
--EXPECTF--
-Warning: json_decode() expects at least 1 parameter, 0 given in %s on line %d
-NULL
NULL
NULL
NULL
diff --git a/ext/json/tests/json_decode_error.phpt b/ext/json/tests/json_decode_error.phpt
index 9906a2b0d4..4089a7897f 100644
--- a/ext/json/tests/json_decode_error.phpt
+++ b/ext/json/tests/json_decode_error.phpt
@@ -6,13 +6,6 @@ Test json_decode() function : error conditions
<?php
echo "*** Testing json_decode() : error conditions ***\n";
-echo "\n-- Testing json_decode() function with no arguments --\n";
-var_dump(json_decode());
-
-echo "\n-- Testing json_decode() function with more than expected no. of arguments --\n";
-$extra_arg = 10;
-var_dump(json_decode('"abc"', true, 512, 0, $extra_arg));
-
echo "\n-- Testing json_decode() function with depth below 0 --\n";
var_dump(json_decode('"abc"', true, -1));
@@ -21,16 +14,6 @@ var_dump(json_decode('"abc"', true, -1));
--EXPECTF--
*** Testing json_decode() : error conditions ***
--- Testing json_decode() function with no arguments --
-
-Warning: json_decode() expects at least 1 parameter, 0 given in %s on line %d
-NULL
-
--- Testing json_decode() function with more than expected no. of arguments --
-
-Warning: json_decode() expects at most 4 parameters, 5 given in %s on line %d
-NULL
-
-- Testing json_decode() function with depth below 0 --
Warning: json_decode(): Depth must be greater than zero in %s on line %d
diff --git a/ext/json/tests/json_last_error_error.phpt b/ext/json/tests/json_last_error_error.phpt
index e733b32854..cd88ef8a9e 100644
--- a/ext/json/tests/json_last_error_error.phpt
+++ b/ext/json/tests/json_last_error_error.phpt
@@ -6,15 +6,14 @@ json_last_error() failures
<?php
var_dump(json_last_error());
-var_dump(json_last_error(true));
-var_dump(json_last_error('some', 4, 'args', 'here'));
+
+try {
+ var_dump(json_last_error(true));
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
?>
---EXPECTF--
+--EXPECT--
int(0)
-
-Warning: json_last_error() expects exactly 0 parameters, 1 given in %s on line %d
-NULL
-
-Warning: json_last_error() expects exactly 0 parameters, 4 given in %s on line %d
-NULL
+json_last_error() expects exactly 0 parameters, 1 given
diff --git a/ext/json/tests/json_last_error_msg_error.phpt b/ext/json/tests/json_last_error_msg_error.phpt
index 719e9fc50c..75b06f72a2 100644
--- a/ext/json/tests/json_last_error_msg_error.phpt
+++ b/ext/json/tests/json_last_error_msg_error.phpt
@@ -6,15 +6,14 @@ json_last_error_msg() failures
<?php
var_dump(json_last_error_msg());
-var_dump(json_last_error_msg(true));
-var_dump(json_last_error_msg('some', 4, 'args', 'here'));
+
+try {
+ var_dump(json_last_error_msg(true));
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
?>
--EXPECTF--
string(8) "No error"
-
-Warning: json_last_error_msg() expects exactly 0 parameters, 1 given in %s on line %d
-NULL
-
-Warning: json_last_error_msg() expects exactly 0 parameters, 4 given in %s on line %d
-NULL
+json_last_error_msg() expects exactly 0 parameters, 1 given