|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-01-20 21:27 UTC] php at tim dot ainfach dot de
Description:
------------
when using a function that is exported by php (ZEND_API) it's not possible to call the function directly. You've to create a reference to the function and then it is possible to call it.
i would expect that it is possible to call the function directly.
these are working fine:
$a = $zend->zend_write; $a("aaa", 3);
($zend->zend_write)("aaa", 3);
(clone $zend->zend_write)("aaa", 3);
this doesn't work -> Attempt to call undefined C function 'zend_write'
$zend->zend_write("aaa", 3);
$a = [$zend, 'zend_write']; $a("aaa", 3);
Test script:
---------------
public static function assertObSame(string $expected, callable $cb)
{
ob_start();
$cb();
$res = ob_get_contents();
ob_end_clean();
static::assertSame($expected, $res);
}
public function testReturnU64()
{
$zend = FFI::cdef("
typedef int (*zend_write_func_t)(const char *str, size_t str_length);
extern zend_write_func_t zend_write;
");
static::assertObSame('aaa', function() use ($zend) { $a = $zend->zend_write; $a("aaa", 3); });
static::assertObSame('aaa', function() use ($zend) { ($zend->zend_write)("aaa", 3); });
static::assertObSame('aaa', function() use ($zend) { (clone $zend->zend_write)("aaa", 3); });
// does not work -> end up in a Attempt to call undefined C function 'zend_write'
static::assertObSame('aaa', function() use ($zend) { $zend->zend_write("aaa", 3); });
static::assertObSame('aaa', function() use ($zend) { $a = [$zend, 'zend_write']; $a("aaa", 3); });
}
Expected result:
----------------
all ways to call zend_write should give the same result (pass the assertion).
Actual result:
--------------
FFI\Exception: Attempt to call undefined C function 'zend_write'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 11:00:01 2025 UTC |
$zend->zend_write is a property, not a method. It's as if you wrote $zend = new stdClass(); $zend->zend_write = function(string $str, int $str_length) { ... };In other other ticket, > struct bug79096 bug79096(void); bug79096 is defined as a function. In this ticket, > extern zend_write_func_t zend_write; zend_write is defined as a variable. Because it actually is a variable. Zend Engine stuff. If you want to call "the zend_write function" you have to find out what the actual underlying function is. I'll spare you the legwork and tell you that (normally) it is php_output_write, implemented in main/output.c. So $zend = FFI::cdef(" int php_output_write(const char *str, size_t str_length); "); $zend->php_output_write("aaa", 3); Of course, doing it this way doesn't get you the actual zend_write "function". It gets you php_output_write. But maybe that's fine for you.