Skip to content

Commit

Permalink
Convert "true" typehint to "bool" (#497)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
shish authored Dec 3, 2024
1 parent 08a716a commit c046795
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions generated/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
2 changes: 2 additions & 0 deletions generator/src/PhpStanFunctions/PhpStanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit c046795

Please sign in to comment.