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
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: dvworkmail2017 at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 15:01:30 2025 UTC