Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP7.4 bool getting confused by boolean #468

Open
leon-v opened this issue Aug 13, 2020 · 1 comment
Open

PHP7.4 bool getting confused by boolean #468

leon-v opened this issue Aug 13, 2020 · 1 comment

Comments

@leon-v
Copy link

leon-v commented Aug 13, 2020

<?
/**
 * [test description]
 * @param  bool|boolean $test [description]
 * @return [type]             [description]
 */
function test(bool $test = true) : bool {
	return false;
}
?>

When a function contains a declared parameter of bool and a default value set to true or false, it get incorrectly detected as boolean and thinks bool is different.

I recommend changing type boolean to bool.

In PHP boolean is a synonym of bool, but boolean values true and false are of type bool.

The importance of adhering to bool over boolean is because:

function test(boolean $test = true){ ... }

would produce a fatal error when the default is used.

References:
https://stackoverflow.com/questions/44009037/php-bool-vs-boolean-type-hinting
https://www.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
https://www.php.net/manual/en/language.types.boolean.php

@8ctopus
Copy link

8ctopus commented Sep 25, 2023

It looks like the fix I recommended also works for this #469

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants