Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Calling FFI::cast() statically is deprecated

cast(), new() and type() are instance methods of the object returned by FFI::cdef() or FFI::load(): each loaded C definition scope has its own set of types, so casting should happen on that specific instance. PHP used to allow calling these methods statically as FFI::cast(), in which case they implicitly operated on an anonymous, definition-less scope. Since PHP 8.3, this static shortcut is deprecated, because it is ambiguous about which set of C declarations is being used.

PHP code

<?php

$ffi = FFI::cdef('typedef struct { int x; int y; } point;');

$mem = $ffi->new('point');

$casted = FFI::cast('int', $mem);

var_dump($casted);

?>

Before

object(FFI\CData:int32)#3 (1) {
  [0]=>
  int(0)
}

After

PHP Deprecated:  Calling FFI::cast() statically is deprecated in /codes/ffiCastStaticDeprecated.php on line 7

Deprecated: Calling FFI::cast() statically is deprecated in /codes/ffiCastStaticDeprecated.php on line 7
object(FFI\CData:int32)#3 (1) {
  [0]=>
  int(0)
}

PHP version change

This behavior changed in 8.3.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat