PHP using boolean when type is bool
Closed this issue · 3 comments
leon-v commented
Current behaviour:
<?
/**
* { function_description }
*
* @param boolean $test The test
*
* @return boolean ( description_of_the_return_value )
*/
function test(bool $test = false) : bool {
return $test;
}
?>
Expected behaviour:
/**
* { function_description }
*
* @param bool $test The test
*
* @return bool ( description_of_the_return_value )
*/
function test(bool $test = false) : bool {
return $test;
}
?>
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 as the default true
is bool
and not boolean
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
20Tauri commented
Thanks,
In the next release:
- "bool" will replace "boolean"
- "int" will replace "integer"
leon-v commented
Awesome! had only just realised integer
was used as well. Was not far off writing up another issue.
Thank you !