Skip to content

Declare tentative return types for ext/json #7051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/enum/json_encode.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum StringFoo: string {
enum CustomFoo implements JsonSerializable {
case Bar;

public function jsonSerialize() {
public function jsonSerialize(): mixed {
return 'Custom ' . $this->name;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/json/json.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function json_last_error_msg(): string {}

interface JsonSerializable
{
/** @return mixed */
public function jsonSerialize();
/** @tentative-return-type */
public function jsonSerialize(): mixed;
}

class JsonException extends Exception
Expand Down
4 changes: 2 additions & 2 deletions ext/json/json_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 6dcef13e46c3dfc2546d3ccc38da07e6c009bbe5 */
* Stub hash: d6577c7d27442643c86e51d462f51dd6e677d509 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_json_encode, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
Expand All @@ -20,7 +20,7 @@ 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_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_JsonSerializable_jsonSerialize, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()


Expand Down
2 changes: 1 addition & 1 deletion ext/json/tests/bug61978.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class JsonTest2 implements JsonSerializable {
public function __construct() {
$this->test = '123';
}
public function jsonSerialize() {
public function jsonSerialize(): mixed {
return array(
'test' => $this->test,
'me' => $this
Expand Down
2 changes: 1 addition & 1 deletion ext/json/tests/bug66025.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bug #66025 (Indent wrong when json_encode() called from jsonSerialize function)
<?php

class Foo implements JsonSerializable {
public function jsonSerialize() {
public function jsonSerialize(): mixed {
return json_encode([1], JSON_PRETTY_PRINT);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/json/tests/bug68992.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bug #68992 (json_encode stacks exceptions thrown by JsonSerializable classes)
<?php

class MyClass implements JsonSerializable {
public function jsonSerialize() {
public function jsonSerialize(): mixed {
throw new Exception('Not implemented!');
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/json/tests/bug71835.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bug #71835 (json_encode sometimes incorrectly detects recursion with JsonSeriali
--FILE--
<?php
class SomeClass implements JsonSerializable {
public function jsonSerialize() {
public function jsonSerialize(): mixed {
return [get_object_vars($this)];
}
}
Expand All @@ -12,7 +12,7 @@ $arr = [$class];
var_dump(json_encode($arr));

class SomeClass2 implements JsonSerializable {
public function jsonSerialize() {
public function jsonSerialize(): mixed {
return [(array)$this];
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/json/tests/bug72069.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var_dump($result);

class A implements \JsonSerializable
{
function jsonSerialize()
function jsonSerialize(): mixed
{
return ['end' => json_decode('', true)];
}
Expand Down
2 changes: 1 addition & 1 deletion ext/json/tests/bug73113.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Also test that the custom exception is not wrapped by ext/json

class JsonSerializableObject implements \JsonSerializable
{
public function jsonSerialize()
public function jsonSerialize(): mixed
{
throw new \Exception('This error is expected');
}
Expand Down
2 changes: 1 addition & 1 deletion ext/json/tests/bug77843.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bug #77843: Use after free with json serializer

class X implements JsonSerializable {
public $prop = "value";
public function jsonSerialize() {
public function jsonSerialize(): mixed {
global $arr;
unset($arr[0]);
var_dump($this);
Expand Down
6 changes: 3 additions & 3 deletions ext/json/tests/serialize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ class NonSerializingTest

class SerializingTest extends NonSerializingTest implements JsonSerializable
{
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return $this->data;
}
}

class ValueSerializingTest extends SerializingTest
{
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return array_values(is_array($this->data) ? $this->data : get_object_vars($this->data));
}
}

class SelfSerializingTest extends SerializingTest
{
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return $this;
}
Expand Down
Binary file not shown.