Bug #79144 [NEW]: FFI call exported function without referencing it

From: Date: Mon, 20 Jan 2020 21:27:50 +0000
Subject: Bug #79144 [NEW]: FFI call exported function without referencing it
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225018@lists.php.net to get a copy of this message
From: php at tim dot ainfach dot de Operating system: OSX 10.14.6 PHP version: 7.4.1 Package: *Extensibility Functions Bug Type: Bug Bug description:FFI call exported function without referencing it 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' -- Edit bug report at https://bugs.php.net/bug.php?id=79144&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79144&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79144&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79144&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79144&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79144&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79144&r=support Expected behavior: https://bugs.php.net/fix.php?id=79144&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79144&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79144&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79144&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79144&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79144&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79144&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79144&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79144&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79144&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79144&r=mysqlcfg

« previous php.bugs (#225018) next »