Fixed bug #54484 (Empty string in json_decode doesn't reset json_last_error()).

This commit is contained in:
Ilia Alshanetsky 2011-06-01 09:44:38 +00:00
parent 6406521a44
commit a7dfb31557
2 changed files with 27 additions and 0 deletions

View File

@ -703,6 +703,8 @@ static PHP_FUNCTION(json_decode)
return;
}
JSON_G(error_code) = 0;
if (!str_len) {
RETURN_NULL();
}

View File

@ -0,0 +1,25 @@
--TEST--
Bug #54484 (Empty string in json_decode doesn't reset json_last_error)
--SKIPIF--
<?php if (!extension_loaded("json")) print "skip"; ?>
--FILE--
<?php
json_decode('{"test":"test"}');
var_dump(json_last_error());
json_decode("");
var_dump(json_last_error());
json_decode("invalid json");
var_dump(json_last_error());
json_decode("");
var_dump(json_last_error());
?>
--EXPECT--
int(0)
int(0)
int(4)
int(0)