Req #81268 [NEW]: intersection type incompatible with nullable props/returns

From: Date: Fri, 16 Jul 2021 15:07:10 +0000
Subject: Req #81268 [NEW]: intersection type incompatible with nullable props/returns
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235088@lists.php.net to get a copy of this message
From:             nicolasgrekas
Operating system: 
PHP version:      8.1Git-2021-07-16 (Git)
Package:          Scripting Engine problem
Bug Type:         Feature/Change Request
Bug description:intersection type incompatible with nullable props/returns

Description:
------------
This code yields "Default value for property of type X&Y may not be
null. Use the nullable type ?X&Y to allow null default value":

class Test {
    public X&Y $y = null;
}

Fine, let's add the suggested "?". But then I get "Parse error: syntax
error, unexpected token "&", expecting variable".

About returning null|intersection, should this be possible?

class Test {
    function foo(): ?X&Y
    {
        return null;
    }
}

Right now it yields a syntax error.


-- 
Edit bug report at https://bugs.php.net/bug.php?id=81268&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81268&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81268&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81268&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81268&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81268&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81268&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81268&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81268&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81268&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81268&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81268&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81268&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81268&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81268&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81268&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81268&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81268&r=mysqlcfg


Thread (12 messages)

« previous php.bugs (#235088) next »