Skip to content

Commit 2501cad

Browse files
Stubs and generated arginfo: remove tentative returns from final methods (#16213)
A tentative return type is used to allow userland code that overrides a method to not include a typehint without a fatal error; this is inapplicable to final methods (including all methods of final classes), which cannot be overridden. Remove the tentative return declarations, and update the build script to complain about future additions.
1 parent c8791e5 commit 2501cad

File tree

5 files changed

+24
-29
lines changed

5 files changed

+24
-29
lines changed

build/gen_stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,9 @@ public function __construct(
12911291
$this->attributes = $attributes;
12921292
$this->framelessFunctionInfos = $framelessFunctionInfos;
12931293
$this->exposedDocComment = $exposedDocComment;
1294+
if ($return->tentativeReturnType && $this->isFinalMethod()) {
1295+
throw new Exception("Tentative return inapplicable for final method");
1296+
}
12941297
}
12951298

12961299
public function isMethod(): bool

ext/reflection/php_reflection.stub.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,16 @@ final class ReflectionGenerator
146146
{
147147
public function __construct(Generator $generator) {}
148148

149-
/** @tentative-return-type */
150149
public function getExecutingLine(): int {}
151150

152-
/** @tentative-return-type */
153151
public function getExecutingFile(): string {}
154152

155-
/** @tentative-return-type */
156153
public function getTrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT): array {}
157154

158-
/** @tentative-return-type */
159155
public function getFunction(): ReflectionFunctionAbstract {}
160156

161-
/** @tentative-return-type */
162157
public function getThis(): ?object {}
163158

164-
/** @tentative-return-type */
165159
public function getExecutingGenerator(): Generator {}
166160

167161
public function isClosed(): bool {}

ext/reflection/php_reflection_arginfo.h

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/spl/spl_directory.stub.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ public function __toString(): string {}
9797
/** @tentative-return-type */
9898
public function __debugInfo(): array {}
9999

100-
/**
101-
* @tentative-return-type
102-
*/
103100
#[\Deprecated(since: '8.2')]
104101
final public function _bad_state_ex(): void {}
105102
}

ext/spl/spl_directory_arginfo.h

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)