char CData can't be directly assigned a number
未关闭
还没有人认领这个 Issue。
Extension: ffi
Feature
Status: Verified
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
The following code:
<?php
$v = FFI::new("char[2]");
$v[0] = 65;
var_dump($v);
Resulted in this output:
Fatal error: Uncaught FFI\Exception: Incompatible types when assigning to type 'char' from PHP 'int' in Command line code:1
Stack trace:
#0 {main}
thrown in Command line code on line 1
But I expected this output instead:
object(FFI\CData:char[2])#1 (2) {
[0]=>
string(1) "A"
[1]=>
string(1) ""
}
It's somewhat weird to have to type cast around, i.e. I could just do a FFI::cast to uint8_t * and it works. But for some reason, char is special. Seems like an arbitrary restriction to me, and it really should accept both.
PHP Version
master
Operating System
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
重现 issue 中的 PHP FFI 示例,并跟踪对 char 类型 CData 值进行赋值的处理过程。找到相关的 FFI 实现和现有的 FFI 测试,然后添加将整数赋给 char 的覆盖测试,并验证是否生成了预期的字符值。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100