Skip to content

Commit c046795

Browse files
authored
Convert "true" typehint to "bool" (#497)
php 8.1 doesn't support "true" as a typehint (The generator will then normally see "function returns bool, except it never returns false because we convert false to exception, which means it only ever returns true, which means the return value is meaningless, so let's convert the return value to void" - which is why this change to the generator results in "returns void" for the generated output)
1 parent 08a716a commit c046795

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

generated/stream.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
* @throws StreamException
2121
*
2222
*/
23-
function stream_context_set_options($context, array $options): true
23+
function stream_context_set_options($context, array $options): void
2424
{
2525
error_clear_last();
2626
$safeResult = \stream_context_set_options($context, $options);
2727
if ($safeResult === false) {
2828
throw StreamException::createFromPhpError();
2929
}
30-
return $safeResult;
3130
}
3231

3332

generator/src/PhpStanFunctions/PhpStanType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ public function getSignatureType(?int $errorType = null): string
148148
$type = ''; // resource cant be typehinted
149149
} elseif (\strpos($type, 'null') !== false) {
150150
$type = ''; // null is a real typehint
151+
} elseif (\strpos($type, 'true') !== false) {
152+
$type = 'bool'; // php8.1 doesn't support "true" as a typehint
151153
}
152154
}
153155

0 commit comments

Comments
 (0)