php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80229 assert_options should have "int" and "bool" for $value parameter PHPDoc
Submitted: 2020-10-13 14:54 UTC Modified: 2020-10-15 10:27 UTC
From: ondrej at mirtes dot cz Assigned:
Status: Closed Package: Reflection related
PHP Version: 8.0.0rc1 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ondrej at mirtes dot cz
New email:
PHP Version: OS:

 

 [2020-10-13 14:54 UTC] 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
{
}

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-13 16:21 UTC] 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-14 11:13 UTC] 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-15 10:27 UTC] 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-17 09:33 UTC] kocsismate@php.net
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
 [2020-10-17 09:41 UTC] kocsismate@php.net
> TBH I think we should just mark this as a "mixed" argument.

I came to the same conclusion a few days ago when I was thinking about this problem. Although, I was slightly concerned that the mixed type is used when it's not 100% correct. But that's sure, it's the closest approximation of string|callable|int|bool|null that we can add easily.
 [2020-10-17 10:01 UTC] kocsismate@php.net
Automatic comment on behalf of kocsismate@woohoolabs.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f076ab0c0cd352cdd70040ba50d40cd229a463ad
Log: Fix #80229: assert_options should have int and bool for parameter PHPDoc
 [2020-10-17 10:01 UTC] kocsismate@php.net
-Status: Open +Status: Closed
 [2020-10-17 10:02 UTC] kocsismate@php.net
Automatic comment on behalf of kocsismate@woohoolabs.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f076ab0c0cd352cdd70040ba50d40cd229a463ad
Log: Fix #80229: assert_options should have int and bool for parameter PHPDoc
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 11:01:31 2025 UTC