in return type class with __invoke method is not a callable
未关闭
还没有人认领这个 Issue。
Category: Engine
Feature
Status: Needs Triage
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 103
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行 issue 中的 PHP reproducer,并检查返回类型兼容性如何处理 callable 类型和类类型。当带有 __invoke 的类和 Closure 可以作为 callable 声明的更窄返回类型被接受,并且兼容性测试覆盖报告的案例时,该 issue 即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100