mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'PHP-7.0'
This commit is contained in:
commit
fa5f28a0a1
3 changed files with 34 additions and 1 deletions
|
@ -254,7 +254,7 @@ static PHP_FUNCTION(json_decode)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_G(error_code) = 0;
|
JSON_G(error_code) = PHP_JSON_ERROR_NONE;
|
||||||
|
|
||||||
if (!str_len) {
|
if (!str_len) {
|
||||||
JSON_G(error_code) = PHP_JSON_ERROR_SYNTAX;
|
JSON_G(error_code) = PHP_JSON_ERROR_SYNTAX;
|
||||||
|
|
|
@ -457,6 +457,7 @@ static void php_json_encode_serializable_object(smart_str *buf, zval *val, int o
|
||||||
zend_class_entry *ce = Z_OBJCE_P(val);
|
zend_class_entry *ce = Z_OBJCE_P(val);
|
||||||
zval retval, fname;
|
zval retval, fname;
|
||||||
HashTable* myht;
|
HashTable* myht;
|
||||||
|
int origin_error_code;
|
||||||
|
|
||||||
if (Z_TYPE_P(val) == IS_ARRAY) {
|
if (Z_TYPE_P(val) == IS_ARRAY) {
|
||||||
myht = Z_ARRVAL_P(val);
|
myht = Z_ARRVAL_P(val);
|
||||||
|
@ -470,8 +471,10 @@ static void php_json_encode_serializable_object(smart_str *buf, zval *val, int o
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ZVAL_STRING(&fname, "jsonSerialize");
|
ZVAL_STRING(&fname, "jsonSerialize");
|
||||||
|
|
||||||
|
origin_error_code = JSON_G(error_code);
|
||||||
if (FAILURE == call_user_function_ex(EG(function_table), val, &fname, &retval, 0, NULL, 1, NULL) || Z_TYPE(retval) == IS_UNDEF) {
|
if (FAILURE == call_user_function_ex(EG(function_table), val, &fname, &retval, 0, NULL, 1, NULL) || Z_TYPE(retval) == IS_UNDEF) {
|
||||||
zend_throw_exception_ex(NULL, 0, "Failed calling %s::jsonSerialize()", ZSTR_VAL(ce->name));
|
zend_throw_exception_ex(NULL, 0, "Failed calling %s::jsonSerialize()", ZSTR_VAL(ce->name));
|
||||||
smart_str_appendl(buf, "null", sizeof("null") - 1);
|
smart_str_appendl(buf, "null", sizeof("null") - 1);
|
||||||
|
@ -479,6 +482,7 @@ static void php_json_encode_serializable_object(smart_str *buf, zval *val, int o
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON_G(error_code) = origin_error_code;
|
||||||
if (EG(exception)) {
|
if (EG(exception)) {
|
||||||
/* Error already raised */
|
/* Error already raised */
|
||||||
zval_ptr_dtor(&retval);
|
zval_ptr_dtor(&retval);
|
||||||
|
|
29
ext/json/tests/bug72069.phpt
Normal file
29
ext/json/tests/bug72069.phpt
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #72069 (Behavior \JsonSerializable different from json_encode)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php if (!extension_loaded("json")) print "skip"; ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$result = json_encode(['end' => json_decode(null, true)]);
|
||||||
|
var_dump($result);
|
||||||
|
|
||||||
|
class A implements \JsonSerializable
|
||||||
|
{
|
||||||
|
function jsonSerialize()
|
||||||
|
{
|
||||||
|
return ['end' => json_decode(null, true)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$a = new A();
|
||||||
|
$toJsonData = $a->jsonSerialize();
|
||||||
|
$result = json_encode($a);
|
||||||
|
var_dump($result);
|
||||||
|
|
||||||
|
$result = json_encode($toJsonData);
|
||||||
|
var_dump($result);
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(12) "{"end":null}"
|
||||||
|
string(12) "{"end":null}"
|
||||||
|
string(12) "{"end":null}"
|
Loading…
Add table
Add a link
Reference in a new issue