char CData can't be directly assigned a number
Open
Nobody has claimed this yet.
Extension: ffi
Feature
Status: Verified
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the PHP FFI example from the issue and trace the handling of assignments to a char CData value. Locate the relevant FFI implementation and existing FFI tests, then add coverage for assigning an integer to char and verify that the expected character value is produced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100