C 코드 및 데이터에 대한 기본 인터페이스

(PHP 7 >= 7.4.0, PHP 8)


소개

이 클래스의 객체는 팩토리 메소드 FFI::cdef(), FFI::load() 또는 FFI::scope()에 의해 생성됩니다. 정의된 C 변수는 FFI 인스턴스의 속성으로 사용할 수 있으며 정의된 C 함수는 FFI 인스턴스의 메서드로 사용할 수 있습니다. 선언된 C 유형은 FFI::new()FFI::type()을 사용하여 새로운 C 데이터 구조를 생성하는 데 사용할 수 있습니다.

FFI 정의 구문 분석 및 공유 라이브러리 로딩은 상당한 시간이 소요될 수 있습니다. 웹 환경에서 각 HTTP 요청에 대해 수행하는 것은 유용하지 않습니다. 그러나 PHP 시작 시 FFI 정의 및 라이브러리를 미리 로드하고 필요할 때 FFI 개체를 인스턴스화할 수 있습니다. 헤더 파일은 특수 FFI_SCOPE 정의(예: #define FFI_SCOPE "foo""", 기본 범위는 "C")를 사용하여 확장할 수 있으며 사전 로드 중에 FFI::load()에 의해 로드됩니다. 이는 영구 바인딩 생성으로 이어집니다. , 이는 FFI::scope()를 통해 다음 모든 요청에 ​​사용할 수 있습니다. 자세한 내용은 전체 PHP/FFI/프리로딩 예제를 참조하세요.

동일한 범위에 둘 이상의 C 헤더 파일을 미리 로드할 수 있습니다.


클래스 개요

                  
class FFI {
  /* Methods */
  public static addr(FFI\CData &$ptr): FFI\CData
  public static alignof(FFI\CData|FFI\CType &$ptr): int
  public static arrayType(FFI\CType $type, array $dimensions): FFI\CType
  public static cast(FFI\CType|string $type, FFI\CData|int|float|bool|null &$ptr): ?FFI\CData
  public cast(FFI\CType|string $type, FFI\CData|int|float|bool|null &$ptr): ?FFI\CData
  public static cdef(string $code = "", ?string $lib = null): FFI
  public static free(FFI\CData &$ptr): void
  public static isNull(FFI\CData &$ptr): bool
  public static load(string $filename): ?FFI
  public static memcmp(string|FFI\CData &$ptr1, string|FFI\CData &$ptr2, int $size): int
  public static memcpy(FFI\CData &$to, FFI\CData|string &$from, int $size): void
  public static memset(FFI\CData &$ptr, int $value, int $size): void
  public static new(FFI\CType|string $type, bool $owned = true, bool $persistent = false): ?FFI\CData
  public new(FFI\CType|string $type, bool $owned = true, bool $persistent = false): ?FFI\CData
  public static scope(string $name): FFI
  public static sizeof(FFI\CData|FFI\CType &$ptr): int
  public static string(FFI\CData &$ptr, ?int $size = null): string
  public static type(string $type): ?FFI\CType
  public type(string $type): ?FFI\CType
  public static typeof(FFI\CData &$ptr): FFI\CType
}
                  
                

목차

  • FFI::addr — C 데이터에 대한 관리되지 않는 포인터를 만듭니다.
  • FFI::alignof — 정렬을 가져옵니다.
  • FFI::arrayType — 새로운 C 배열 유형을 동적으로 생성
  • FFI::cast — C 유형 캐스트를 수행합니다.
  • FFI::cdef — 새 FFI 개체를 만듭니다.
  • FFI::free — 관리되지 않는 데이터 구조를 해제합니다.
  • FFI::isNull — FFI\CData가 널 포인터인지 확인합니다.
  • FFI::load — C 헤더 파일에서 C 선언을 로드합니다.
  • FFI::memcmp — 메모리 영역 비교
  • FFI::memcpy — 한 메모리 영역을 다른 메모리 영역으로 복사
  • FFI::memset — 메모리 영역을 채움
  • FFI::new — C 데이터 구조를 만듭니다.
  • FFI::scope — 미리 로드하는 동안 구문 분석된 C 선언으로 FFI 개체를 인스턴스화합니다.
  • FFI::sizeof — C 데이터 또는 유형의 크기를 가져옵니다.
  • FFI::string — 메모리 영역에서 PHP 문자열을 생성합니다.
  • FFI::type — C 선언에서 FFI\CType 개체를 만듭니다.
  • FFI::typeof — FFI\CData의 FFI\CType을 가져옵니다.