php-src/Zend/tests/gh8841.phpt
Niels Dossche cf9b030a57 Fix GH-8841: php-cli core dump calling a badly formed function
It's actually not php-cli specific, nor SAPI specific.
We should delay the registration of the function into the function table
until after the compilation was successful, otherwise the function is
mistakingly registered and a NULL dereference will happen when trying to
call it.

I based my test of Nikita's test, so credits to him for the test:
https://github.com/php/php-src/pull/8933#issuecomment-1259881008

Closes GH-10989.
2023-04-01 19:43:09 +02:00

31 lines
709 B
PHP

--TEST--
GH-8841 (php-cli core dump calling a badly formed function)
--FILE--
<?php
register_shutdown_function(function() {
echo "Before calling g()\n";
g(1);
echo "After calling g()\n";
});
register_shutdown_function(function() {
echo "Before calling f()\n";
f(1);
echo "After calling f()\n";
});
eval('function g($x): int { return $x; }');
eval('function f($x): void { return $x; }');
?>
--EXPECTF--
Fatal error: A void function must not return a value in %s on line %d
Before calling g()
After calling g()
Before calling f()
Fatal error: Uncaught Error: Call to undefined function f() in %s:%d
Stack trace:
#0 [internal function]: {closure}()
#1 {main}
thrown in %s on line %d