Deprecation errors are inconsistently triggered for underscore class aliases
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
The following code:
<?php
namespace Foo {
class __ {}
}
namespace Bar {
class _ {} // Deprecated
}
namespace {
class __ {}
class_alias('Foo\__', 'Foo\_'); // Is this meant to be deprecated?
class_alias('__', '_'); // Deprecated
}
namespace Baz {
use Foo\_;
}
namespace Qux {
use Foo\__ as _; // Is this meant to be deprecated?
}
Resulted in this output:
Deprecated: Using "_" as a class name is deprecated since 8.4 in /in/ZZMJs on line 8
Deprecated: Using "_" as a class alias is deprecated since 8.4 in /in/ZZMJs on line 15
But I expected this output instead:
Deprecated: Using "_" as a class name is deprecated since 8.4 in /in/ZZMJs on line 8
Deprecated: Using "_" as a class alias is deprecated since 8.4 in /in/ZZMJs on line 14
Deprecated: Using "_" as a class alias is deprecated since 8.4 in /in/ZZMJs on line 15
Deprecated: Using "_" as a class alias is deprecated since 8.4 in /in/ZZMJs on line 23
I encountered this issue while trying to migrate a large closed source project to PHP 8.4. The namespaced _ class was used as a wrapper for the gettext _ function (eg new _("string")), to delay performing the translation of cached content until the http response is stringified. The class had ~35k instantiations in source control and more instances in compressed + serialized database records. This made class aliases a potentially appealing solution, but I understand from @Girgias that these not emitting deprecation errors is an oversight.
PHP Version
8.4.1 - 8.4.6 on 3v4l
Operating System
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的 PHP 8.4 复现代码,并比较类声明、class_alias() 调用和 namespaced use alias 的弃用行为。跟踪处理类别名和命名空间导入的解释器路径,然后添加回归测试覆盖,表明预期的四种下划线情况都会发出弃用通知。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100