Bug #80229 [PATCH]: assert_options should have "int" and "bool" for $value parameter PHPDoc

From: Date: Sat, 17 Oct 2020 09:33:48 +0000
Subject: Bug #80229 [PATCH]: assert_options should have "int" and "bool" for $value parameter PHPDoc
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229685@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80229&edit=1 ID: 80229 Patch added by: kocsismate@php.net Reported by: ondrej at mirtes dot cz Summary: assert_options should have "int" and "bool" for $value parameter PHPDoc Status: Open Type: Bug Package: Reflection related PHP Version: 8.0.0rc1 Block user comment: N Private report: N New Comment: The following pull request has been associated: Patch Name: Fix #80229: assert_options should have int and bool for parameter PHPDoc On GitHub: https://github.com/php/php-src/pull/6348 Patch: https://github.com/php/php-src/pull/6348.patch Previous Comments: ------------------------------------------------------------------------ [2020-10-15 10:27:12] nikic@php.net The problem here is that assert_option internally treats the value as a string, which is why it was documented as such. Of course, the user would rather pass int/bool. This is a similar situation to ini_set, which also accepts a string, while something else might be more convenient. TBH I think we should just mark this as a "mixed" argument. That matches the semantics more closely than some weird string|callable|int|bool|null union. ------------------------------------------------------------------------ [2020-10-14 11:13:54] ondrej at mirtes dot cz I don't think this is related to strict_types: https://3v4l.org/Q2EuC The PHP documentation even talks about 1 (integer) to be a default value, but "int" is missing in the PHPDoc. ------------------------------------------------------------------------ [2020-10-13 16:21:16] cmb@php.net There are likely some other functions with the same issue. The problem here is strict_types on vs. off. In case of the latter the current signature is correct; in case of the former, int and bool are indeed missing. Not sure how to resolve this. ------------------------------------------------------------------------ [2020-10-13 14:54:19] ondrej at mirtes dot cz Description: ------------ The function assert_options accepts integers and booleans as the second argument. Currently according to the stub's PHPDoc, it only accepts strings, callables and null. The PHPDoc should be corrected. I guess the assert_options function can be called with either "1" or "true" for the same result... Expected result: ---------------- /** @param string|callable|int|bool|null $value */ function assert_options(int $option, $value = UNKNOWN) : array|object|int|string|null { } Actual result: -------------- /** @param string|callable|null $value */ function assert_options(int $option, $value = UNKNOWN) : array|object|int|string|null { } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80229&edit=1

« previous php.bugs (#229685) next »