I want to explore PHP variables on C level with FFI. Is it possible?
I wrote code, but it doesn't work correctly.
php_ffi.cpp
#include "zend_types.h"
#include "main/php.h"
int main() {}
extern "C" void print_zval_info(zval zv) {
printf("type: %d\n", Z_TYPE(zv));
}
test.php
<?php
$cpp_ffi = \FFI::cdef(
"void print_zval_info(zval zv);",
__DIR__ . "/php_ffi.so");
$a = 1;
$cpp_ffi->print_zval_info($a);
How to reproduce:
git clone git@github.com:php/php-src.git && cd php-src
./buildconf
./configure --enable-debug --with-ffi
g++ -g -fPIC -shared -I . -I Zend -I main -I TSRM php_ffi.cpp -o php_ffi.so
php test.php