Skip to content

char CData can't be directly assigned a number #8355

Open
@bwoebi

Description

@bwoebi

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions