php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70833 Scalar type hinting works with bool but not with boolean
Submitted: 2015-11-02 09:24 UTC Modified: 2015-11-26 19:58 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sam at rmcreative dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.0RC6 OS: Any
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: sam at rmcreative dot ru
New email:
PHP Version: OS:

 

 [2015-11-02 09:24 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-02 10:03 UTC] php at developerjack dot com
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.
 [2015-11-26 19:41 UTC] webmaster at tubo-world dot de
As stated, the aliases are not meant to be supported according to the RFC. This can be closed.
 [2015-11-26 19:58 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2015-11-26 19:58 UTC] nikic@php.net
As per the previous comments, not supporting aliases is deliberate, so closing as not a bug.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 17:00:01 2026 UTC