From c046795df6ffd67b16b4e8960891bded93bf8af8 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 3 Dec 2024 13:12:51 +0000 Subject: [PATCH] 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) --- generated/stream.php | 3 +-- generator/src/PhpStanFunctions/PhpStanType.php | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/generated/stream.php b/generated/stream.php index e5e0ce9c..81c76791 100644 --- a/generated/stream.php +++ b/generated/stream.php @@ -20,14 +20,13 @@ * @throws StreamException * */ -function stream_context_set_options($context, array $options): true +function stream_context_set_options($context, array $options): void { error_clear_last(); $safeResult = \stream_context_set_options($context, $options); if ($safeResult === false) { throw StreamException::createFromPhpError(); } - return $safeResult; } diff --git a/generator/src/PhpStanFunctions/PhpStanType.php b/generator/src/PhpStanFunctions/PhpStanType.php index dfe8b0b2..33ec387c 100644 --- a/generator/src/PhpStanFunctions/PhpStanType.php +++ b/generator/src/PhpStanFunctions/PhpStanType.php @@ -148,6 +148,8 @@ public function getSignatureType(?int $errorType = null): string $type = ''; // resource cant be typehinted } elseif (\strpos($type, 'null') !== false) { $type = ''; // null is a real typehint + } elseif (\strpos($type, 'true') !== false) { + $type = 'bool'; // php8.1 doesn't support "true" as a typehint } }