php / php/php-src

in return type class with __invoke method is not a callable

Offen
#18,161 7 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Category: Engine Feature Status: Needs Triage
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.1k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

Description

The following code:

<?php
interface I {
    public function test(): callable;
}
class Invokable {
    public function __invoke() {}
}
var_dump(is_callable(new Invokable()));
class C implements I {
    public function test(): Invokable {}
}

Resulted in this output:

bool(true)

Fatal error: Declaration of C::test(): Invokable must be compatible with I::test(): callable in /in/PfBWX on line 10

Process exited with code 255.

Methods should be able to restrict callable return types from interfaces and parent classes to more specific types that unconditionally fall within the callable type. Any class or interface that contains an __invoke method should be considered a callable type an be allowed as a more specific subtype of callable in subclasses. Also \Closure should be allowed as well.

PHP Version

8.4.5

Operating System

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den PHP-Reproducer aus dem Issue auszuführen, und untersuche, wie die Rückgabetyp-Kompatibilität callable- und Klassentypen behandelt. Das Issue ist abgeschlossen, wenn Klassen mit __invoke und Closure als engere Rückgabetypen für callable-Deklarationen akzeptiert werden und Kompatibilitätstests die gemeldeten Fälle abdecken.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, php
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.