php / php/doc-en

Impossible intersection types are not checked at compile time

Open
#3,706 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Status: Needs Triage
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Foo&Bar parameter example from the issue and compare it with the documented behavior of PHP intersection types and never. No documentation file or test is named; done should be a documented resolution of the reported compile-time behavior or a confirmed correction to the report.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.