Bug #70833 [Com]: Scalar type hinting works with bool but not with boolean
| From: | php at developerjack dot com | Date: | Mon, 02 Nov 2015 10:03:49 +0000 |
| Subject: | Bug #70833 [Com]: Scalar type hinting works with bool but not with boolean | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196970@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70833&edit=1
ID: 70833
Comment by: php at developerjack dot com
Reported by: sam at rmcreative dot ru
Summary: Scalar type hinting works with bool but not with
boolean
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Any
PHP Version: 7.0.0RC6
Block user comment: N
Private report: N
New Comment:
My understanding is only one scalar type should exist.
From the RFC:
https://wiki.php.net/rfc/scalar_type_hints_v5
Heading: "Type Aliases Should Not Be Supported"
> This proposal takes the stance that there should be one obvious type. Therefore, no aliases are
> supported.
I cannot remember a separate RFC to reserve boolean (or integer for that matter) for use.
Previous Comments:
------------------------------------------------------------------------
[2015-11-02 09:24:28] sam at rmcreative dot ru
Description:
------------
You can cast to boolean using either (bool)$var or (boolean)$var. In scalar type hints currently
only bool could be used which is inconsistent.
Test script:
---------------
<?php
$boolean = 1;
$boolean = (boolean) $boolean;
function dump_boolean(boolean $var)
{
var_dump($var);
}
dump_boolean($boolean);
// https://3v4l.org/Cdtoe
Expected result:
----------------
I'd expect both boolean and bool work as scalar type hint because both work well for type
casting.
Actual result:
--------------
https://3v4l.org/egb59
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70833&edit=1