com php-src: Merge branch 'PHP-7.0' into PHP-7.1: ext/json/json _encoder.c ext/json/tests/bug68992.phpt

From: Date: Mon, 19 Sep 2016 14:42:53 +0000
Subject: com php-src: Merge branch 'PHP-7.0' into PHP-7.1: ext/json/json _encoder.c ext/json/tests/bug68992.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-94584@lists.php.net to get a copy of this message
Commit: 7c7dc62c11da6e1e10452f96c1c8b823e5bb468c Author: Julien Pauli <jpauli@php.net> Mon, 19 Sep 2016 16:12:33 +0200 Parents: d8d409135777091302d7c8f905f3f093d95c7b0b c4f3ea10e49a2a44e767ce38c57329934a6bbaba Branches: PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7c7dc62c11da6e1e10452f96c1c8b823e5bb468c Log: Merge branch 'PHP-7.0' into PHP-7.1 * PHP-7.0: Do not wrap user exception in case of custom JSON serialization Conflicts: ext/json/json_encoder.c Changed paths: MM ext/json/json_encoder.c MA ext/json/tests/bug68992.phpt Diff: diff --cc ext/json/json_encoder.c index 8fd2f23,8da2761..f946748 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@@ -487,13 -467,12 +487,15 @@@ static int php_json_encode_serializable 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) { - zend_throw_exception_ex(NULL, 0, "Failed calling %s::jsonSerialize()", ZSTR_VAL(ce->name)); + if (!EG(exception)) { + zend_throw_exception_ex(NULL, 0, "Failed calling %s::jsonSerialize()", ZSTR_VAL(ce->name)); + } - smart_str_appendl(buf, "null", sizeof("null") - 1); zval_ptr_dtor(&fname); - return; + + if (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { + smart_str_appendl(buf, "null", 4); + } + return FAILURE; } JSON_G(error_code) = origin_error_code; diff --cc ext/json/tests/bug68992.phpt index 0fc41ec,0000000..06448bb mode 100644,000000..100644 --- a/ext/json/tests/bug68992.phpt +++ b/ext/json/tests/bug68992.phpt @@@ -1,30 -1,0 +1,29 @@@ +--TEST-- +Bug #68992 (json_encode stacks exceptions thrown by JsonSerializable classes) +--SKIPIF-- +<?php +if (!extension_loaded('json')) die('skip'); +?> +--FILE-- +<?php + +class MyClass implements JsonSerializable { + public function jsonSerialize() { + throw new Exception('Not implemented!'); + } +} +$classes = []; +for($i = 0; $i < 5; $i++) { + $classes[] = new MyClass(); +} + +try { + json_encode($classes); +} catch(Exception $e) { + do { + printf("%s (%d) [%s]\n", $e->getMessage(), $e->getCode(), get_class($e)); + } while ($e = $e->getPrevious()); +} +?> +--EXPECT-- - Failed calling MyClass::jsonSerialize() (0) [Exception] +Not implemented! (0) [Exception]

« previous php.cvs (#94584) next »