FFI::cast
(PHP 7 >= 7.4.0, PHP 8)
FFI::cast — Performs a C type cast
说明
FFI::cast() creates a new FFI\CData
object, that references the same C data structure, but is associated with a different type.
The resulting object does not own the C data, and the source ptr
must survive the result. The C type may be specified as a string with any
valid C type declaration or as FFI\CType object, created before.
Any type declared for the instance is allowed.
参数
返回值
Returns the freshly created FFI\CData object.
更新日志
版本 | 说明 |
---|---|
8.3.0 | Calling FFI::cast() statically is now deprecated. |
+添加备注
用户贡献的备注 1 note
Yaner ¶
2 years ago
For example, stdlib.h headfile defines a function called "system()" in Linux: extern int system (const char *__command) __wur;
And we can call it using FFI extension:
<?php
$ffi_obj = FFI::cdef('int system(char *command);')
$ffi_obj->system('whoami');
?>
Then execute the php script as if we were calling the real C `system()`:
$ whoami
> root
$ php demo.php
> root