Skip to content

Commit 5fbc676

Browse files
committed
Remove shim for iterable BC
1 parent 55860a2 commit 5fbc676

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

Zend/zend_compile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,6 @@ static zend_string *resolve_class_name(zend_string *name, zend_class_entry *scop
11891189

11901190
zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scope) {
11911191
zend_string *str = NULL;
1192-
uint32_t type_mask = ZEND_TYPE_PURE_MASK(type);
1193-
bool has_name = ZEND_TYPE_HAS_NAME(type);
11941192

11951193
if (ZEND_TYPE_HAS_LIST(type)) {
11961194
zend_type *list_type;
@@ -1201,10 +1199,12 @@ zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scop
12011199
str = add_type_string(str, resolved, is_intersection);
12021200
zend_string_release(resolved);
12031201
} ZEND_TYPE_LIST_FOREACH_END();
1204-
} else if (has_name) {
1202+
} else if (ZEND_TYPE_HAS_NAME(type)) {
12051203
str = resolve_class_name(ZEND_TYPE_NAME(type), scope);
12061204
}
12071205

1206+
uint32_t type_mask = ZEND_TYPE_PURE_MASK(type);
1207+
12081208
if (type_mask == MAY_BE_ANY) {
12091209
str = add_type_string(str, ZSTR_KNOWN(ZEND_STR_MIXED), /* is_intersection */ false);
12101210

ext/reflection/php_reflection.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ typedef enum {
13201320
} reflection_type_kind;
13211321

13221322
/* For backwards compatibility reasons, we need to return T|null style unions
1323-
* and transformation from iterable to Traversable|array
1323+
* ~~and transformation from iterable to Traversable|array~~
13241324
* as a ReflectionNamedType. Here we determine what counts as a union type and
13251325
* what doesn't. */
13261326
static reflection_type_kind get_type_kind(zend_type type) {
@@ -1336,9 +1336,11 @@ static reflection_type_kind get_type_kind(zend_type type) {
13361336

13371337
if (ZEND_TYPE_IS_COMPLEX(type)) {
13381338
/* BC support for 'iterable' type */
1339+
/*
13391340
if (UNEXPECTED(ZEND_TYPE_IS_ITERABLE_FALLBACK(type))) {
13401341
return NAMED_TYPE;
13411342
}
1343+
*/
13421344
if (type_mask_without_null != 0) {
13431345
return UNION_TYPE;
13441346
}

ext/reflection/tests/iterable_Reflection.phpt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,33 @@ iterable Type in Reflection
33
--FILE--
44
<?php
55

6-
$functions = [
7-
function(): iterable {},
8-
];
6+
$function = function(): iterable {};
97

10-
foreach ($functions as $function) {
11-
$reflectionFunc = new ReflectionFunction($function);
12-
$returnType = $reflectionFunc->getReturnType();
13-
var_dump($returnType->getName());
8+
$reflectionFunc = new ReflectionFunction($function);
9+
$returnType = $reflectionFunc->getReturnType();
10+
var_dump($returnType::class);
11+
foreach ($returnType->getTypes() as $type) {
12+
var_dump($type->getName());
1413
}
1514

16-
1715
class PropIterableTypeTest {
1816
public iterable $iterable;
1917
}
2018

2119
$reflector = new ReflectionClass(PropIterableTypeTest::class);
2220

23-
foreach ($reflector->getProperties() as $name => $property) {
24-
if ($property->hasType()) {
25-
printf("public %s $%s;\n",
26-
$property->getType()->getName(), $property->getName());
27-
} else printf("public $%s;\n", $property->getName());
21+
[$property] = $reflector->getProperties();
22+
$iterableType = $property->getType();
23+
var_dump($iterableType::class);
24+
foreach ($iterableType->getTypes() as $type) {
25+
var_dump($type->getName());
2826
}
2927

3028
?>
3129
--EXPECT--
32-
string(17) "Traversable|array"
33-
public Traversable|array $iterable;
30+
string(19) "ReflectionUnionType"
31+
string(11) "Traversable"
32+
string(5) "array"
33+
string(19) "ReflectionUnionType"
34+
string(11) "Traversable"
35+
string(5) "array"

0 commit comments

Comments
 (0)