Skip to content

Commit 2f25f9d

Browse files
committed
Update implementation
1 parent 01aa4cb commit 2f25f9d

34 files changed

+84
-398
lines changed

Zend/tests/enum/json_encode.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum StringFoo: string {
1818
enum CustomFoo implements JsonSerializable {
1919
case Bar;
2020

21-
public function jsonSerialize() {
21+
public function jsonSerialize(): mixed {
2222
return 'Custom ' . $this->name;
2323
}
2424
}

Zend/tests/iterator_key_by_ref.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Iterator::key() with by-ref return
33
--FILE--
44
<?php
55
class Test extends ArrayIterator {
6-
function &key() {
6+
function &key(): mixed {
77
return $foo;
88
}
99
}

Zend/tests/type_declarations/variance/optional_return_type/incompatible_return_type.phpt

Lines changed: 0 additions & 28 deletions
This file was deleted.

Zend/tests/type_declarations/variance/optional_return_type/incompatible_return_type2.phpt

Lines changed: 0 additions & 28 deletions
This file was deleted.

Zend/tests/type_declarations/variance/optional_return_type/incompatible_return_type3.phpt

Lines changed: 0 additions & 34 deletions
This file was deleted.

Zend/tests/type_declarations/variance/optional_return_type/incompatible_return_type4.phpt

Lines changed: 0 additions & 24 deletions
This file was deleted.

Zend/tests/type_declarations/variance/optional_return_type/missing_return_type.phpt

Lines changed: 0 additions & 17 deletions
This file was deleted.

Zend/tests/type_declarations/variance/optional_return_type/suppressed_incompatible_return_type.phpt

Lines changed: 0 additions & 28 deletions
This file was deleted.

Zend/tests/type_declarations/variance/optional_return_type/suppressed_incompatible_return_type2.phpt

Lines changed: 0 additions & 28 deletions
This file was deleted.

Zend/tests/type_declarations/variance/optional_return_type/suppressed_incompatible_return_type3.phpt

Lines changed: 0 additions & 38 deletions
This file was deleted.

Zend/tests/type_declarations/variance/optional_return_type/suppressed_incompatible_return_type4.phpt

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Test that the notice can be suppressed when the return type/value of the overriding method is incompatible with the tentative return type/value of the overridden method
3+
--FILE--
4+
<?php
5+
6+
class MyDateTime extends DateTime
7+
{
8+
/**
9+
* @return DateTime|false
10+
*/
11+
#[ReturnTypeWillChange]
12+
public function modify(string $modifier) {
13+
return false;
14+
}
15+
}
16+
17+
$date = new MyDateTime("2021-01-01 00:00:00");
18+
var_dump($date->modify("+1 sec"));
19+
?>
20+
--EXPECT--
21+
bool(false)

Zend/zend_attributes.c

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
#include "zend_smart_str.h"
2525

2626
ZEND_API zend_class_entry *zend_ce_attribute;
27-
ZEND_API zend_class_entry *zend_ce_tentative_return_type_attribute;
28-
ZEND_API zend_class_entry *zend_ce_suppress_tentative_return_type_notice_attribute;
27+
ZEND_API zend_class_entry *zend_ce_return_type_will_change_attribute;
2928

3029
static HashTable internal_attributes;
3130

@@ -57,17 +56,10 @@ void validate_attribute(zend_attribute *attr, uint32_t target, zend_class_entry
5756
}
5857
}
5958

60-
void validate_tentative_return_type_attribute(zend_attribute *attr, uint32_t target, zend_class_entry *scope)
59+
void validate_return_type_will_change_attribute(zend_attribute *attr, uint32_t target, zend_class_entry *scope)
6160
{
6261
if (target != ZEND_ATTRIBUTE_TARGET_METHOD) {
63-
zend_error(E_COMPILE_ERROR, "Only methods can be marked with #[TentativeReturnType]");
64-
}
65-
}
66-
67-
void validate_suppress_tentative_return_type_notice_attribute(zend_attribute *attr, uint32_t target, zend_class_entry *scope)
68-
{
69-
if (target != ZEND_ATTRIBUTE_TARGET_METHOD) {
70-
zend_error(E_COMPILE_ERROR, "Only methods can be marked with #[SuppressTentativeReturnTypeNotice]");
62+
zend_error(E_COMPILE_ERROR, "Only methods can be marked with #[ReturnTypeWillChange]");
7163
}
7264
}
7365

@@ -83,12 +75,7 @@ ZEND_METHOD(Attribute, __construct)
8375
ZVAL_LONG(OBJ_PROP_NUM(Z_OBJ_P(ZEND_THIS), 0), flags);
8476
}
8577

86-
ZEND_METHOD(TentativeReturnType, __construct)
87-
{
88-
ZEND_PARSE_PARAMETERS_NONE();
89-
}
90-
91-
ZEND_METHOD(SuppressTentativeReturnTypeNotice, __construct)
78+
ZEND_METHOD(ReturnTypeWillChange, __construct)
9279
{
9380
ZEND_PARSE_PARAMETERS_NONE();
9481
}
@@ -305,13 +292,9 @@ void zend_register_attribute_ce(void)
305292
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("TARGET_ALL"), ZEND_ATTRIBUTE_TARGET_ALL);
306293
zend_declare_class_constant_long(zend_ce_attribute, ZEND_STRL("IS_REPEATABLE"), ZEND_ATTRIBUTE_IS_REPEATABLE);
307294

308-
zend_ce_tentative_return_type_attribute = register_class_TentativeReturnType();
309-
attr = zend_internal_attribute_register(zend_ce_tentative_return_type_attribute, ZEND_ATTRIBUTE_TARGET_METHOD);
310-
attr->validator = validate_tentative_return_type_attribute;
311-
312-
zend_ce_suppress_tentative_return_type_notice_attribute = register_class_SuppressTentativeReturnTypeNotice();
313-
attr = zend_internal_attribute_register(zend_ce_suppress_tentative_return_type_notice_attribute, ZEND_ATTRIBUTE_TARGET_METHOD);
314-
attr->validator = validate_suppress_tentative_return_type_notice_attribute;
295+
zend_ce_return_type_will_change_attribute = register_class_ReturnTypeWillChange();
296+
attr = zend_internal_attribute_register(zend_ce_return_type_will_change_attribute, ZEND_ATTRIBUTE_TARGET_METHOD);
297+
attr->validator = validate_return_type_will_change_attribute;
315298
}
316299

317300
void zend_attributes_shutdown(void)

Zend/zend_attributes.stub.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ final class Attribute
99
public function __construct(int $flags = Attribute::TARGET_ALL) {}
1010
}
1111

12-
final class TentativeReturnType
13-
{
14-
public function __construct() {}
15-
}
16-
17-
final class SuppressTentativeReturnTypeNotice
12+
final class ReturnTypeWillChange
1813
{
1914
public function __construct() {}
2015
}

0 commit comments

Comments
 (0)