php / php/php-src

char CData can't be directly assigned a number

オープン
#8,355 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Extension: ffi Feature Status: Verified
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue の PHP FFI の例を再現し、char 型の CData 値への代入の処理を追跡します。関連する FFI の実装と既存の FFI テストを見つけ、整数を char に代入する場合のカバレッジを追加して、期待される文字値が生成されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。