Convert "true" typehint to "bool"#497
Conversation
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)
| * | ||
| */ | ||
| function stream_context_set_options($context, array $options): true | ||
| function stream_context_set_options($context, array $options): void |
There was a problem hiding this comment.
As well as translating "return false" into "throw exception", the generator also translates "return true" into "return void" (presumably because true on success / false on error and void on success / Exception on error are relatively-standard patterns whereas true on success / Exception on error is weird and misleading)
There was a problem hiding this comment.
I guess this breaks the types and analysis with PHPStan and similar?
"always returns true" and "does not return anything" are very different things
There was a problem hiding this comment.
I'm not sure, but this is how all the other functions are being generated already, and it seems to work -- this PR doesn't change the behaviour of "return bool" functions, it only turns "return true" into "return bool" and leaves the rest of the process untouched
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)