php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80508 Union types in class not working properly
Submitted: 2020-12-13 02:05 UTC Modified: 2020-12-13 02:07 UTC
From: dvworkmail2017 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 8.0.0 OS: ubuntu 20
Private report: No CVE-ID: None
 [2020-12-13 02:05 UTC] dvworkmail2017 at gmail dot com
Description:
------------
Union types in class return double instead type error

Test script:
---------------
class Number
{
    public function __construct(
        private int | float $number
    ) {

        print_r(gettype($number));
        exit();
    }
}

new Number("1.0");

Expected result:
----------------
Excepted Output should be: TypeError


Actual result:
--------------
Current Output is: double

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-13 02:07 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2020-12-13 02:07 UTC] requinix@php.net
You didn't enable strict_types.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Jul 04 03:03:50 2022 UTC