Skip to content

Impossible intersection types are not checked at compile time #3706

Open
@Kenny1911

Description

@Kenny1911

Description

The following code:

<?php

class Foo {}

class Bar {}

function test(Foo&Bar $arg): void {}

https://3v4l.org/sKIr0

I use intersection type Foo&Bar for function argument.

Actually, there is no type that would be comparable to Foo&Bar. Therefore, Foo&Bar is equivalent to the type never.

If i use never in argument type, PHP Fatal Error will be thrown. But if i use Foo&Bar, no error will occur.

Resulted in this output:

Nothing

But I expected this output instead:

PHP Fatal error:  Foo&Bar cannot be used as a parameter type

PHP Version

PHP 8.3.11

Operating System

Ubuntu 20.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions