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::new() statically is deprecated

new(), cast() 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 allocating a new value should happen on that specific instance. PHP used to allow calling these methods statically as FFI::new(), 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::cdef('typedef struct { int x; int y; } point;');

$mem = FFI::new('point');

var_dump($mem);

?>

Before

object(FFI\CData:struct <anonymous>)#2 (2) {
  ["x"]=>
  int(0)
  ["y"]=>
  int(0)
}

After

PHP Deprecated:  Calling FFI::new() statically is deprecated in /codes/ffiNewStaticDeprecated.php on line 5

Deprecated: Calling FFI::new() statically is deprecated in /codes/ffiNewStaticDeprecated.php on line 5
object(FFI\CData:struct <anonymous>)#2 (2) {
  ["x"]=>
  int(0)
  ["y"]=>
  int(0)
}

PHP version change

This behavior changed in 8.3.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat