Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit be69262

Browse files
gen_stub: drop support for @refcount 0 with scalar return (#16505)
* gen_stub: drop support for `@refcount 0` with scalar return Currenty, if `@refcount` is omitted, it is assumed to be 0 for scalar return types and "N" otherwise. On the other hand, if `@refcount` is provided, for a scalar return type it *must* be 0, and for a non-scalar return type it *must not* be 0. In other words, the ref count will be 0 if and only if the return type is scalar, regardless of whether the `@refcount` tag is used. In that case, adding `@refcount 0` does nothing, and since its presence suggests it does something (why would a developer add code that does nothing?) it is confusing and should be removed. As it happens, there are currently no uses of `@refcount 0` in php-src, but why should we allow future uses? Removing this support also allows simplifying the code a bit.
1 parent 8b68274 commit be69262

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

‎build/gen_stub.php‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,7 @@ class ReturnInfo {
11591159
const REFCOUNT_1 = "1";
11601160
const REFCOUNT_N = "N";
11611161

1162-
const REFCOUNTS = [
1163-
self::REFCOUNT_0,
1162+
const REFCOUNTS_NONSCALAR = [
11641163
self::REFCOUNT_1,
11651164
self::REFCOUNT_N,
11661165
];
@@ -1204,16 +1203,14 @@ private function setRefcount(?string $refcount): void
12041203
return;
12051204
}
12061205

1207-
if (!in_array($refcount, ReturnInfo::REFCOUNTS, true)) {
1208-
throw new Exception("@refcount must have one of the following values: \"0\", \"1\", \"N\", $refcount given");
1209-
}
1210-
1211-
if ($isScalarType && $refcount !== self::REFCOUNT_0) {
1212-
throw new Exception('A scalar return type of "' . $type->__toString() . '" must have a refcount of "' . self::REFCOUNT_0 . '"');
1206+
if ($isScalarType) {
1207+
throw new Exception(
1208+
"@refcount on functions returning scalar values is redundant and not permitted"
1209+
);
12131210
}
12141211

1215-
if (!$isScalarType && $refcount === self::REFCOUNT_0) {
1216-
throw new Exception('A non-scalar return type of "' . $type->__toString() . '" cannot have a refcount of "' . self::REFCOUNT_0 . '"');
1212+
if (!in_array($refcount, ReturnInfo::REFCOUNTS_NONSCALAR, true)) {
1213+
throw new Exception("@refcount must have one of the following values: \"1\", \"N\", $refcount given");
12171214
}
12181215

12191216
$this->refcount = $refcount;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /