Skip to content

PHP7.4 bool getting confused by boolean #468

Description

@leon-v
<?
/**
 * [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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions