Skip to content

ext/pcntl: fix declared signature of pcntl_signal($restart_syscalls) - #23531

Open
lacatoire wants to merge 3 commits into
php:masterfrom
lacatoire:fix/pcntl-signal-restart-syscalls-stub
Open

ext/pcntl: fix declared signature of pcntl_signal($restart_syscalls)#23531
lacatoire wants to merge 3 commits into
php:masterfrom
lacatoire:fix/pcntl-signal-restart-syscalls-stub

Conversation

@lacatoire

Copy link
Copy Markdown
Member

pcntl_signal() parses its third argument with Z_PARAM_BOOL_OR_NULL(), so null is accepted, and null is also what selects the SIGALRM specific default of false:

if (restart_syscalls_is_null && signo == SIGALRM) {
    restart_syscalls = 0;
}

The stub, however, declared a non-nullable bool defaulting to true, so Reflection reported a signature the implementation does not honour:

$p = (new ReflectionFunction('pcntl_signal'))->getParameters()[2];

var_dump($p->allowsNull());        // bool(false)
var_dump($p->getDefaultValue());   // bool(true)

pcntl_signal(SIGALRM, fn() => null, null);
echo "null accepted\n";            // no TypeError, no deprecation

Every other Z_PARAM_BOOL_OR_NULL() user declares a nullable parameter defaulting to nullimageinterlace(), json_decode(), libxml_use_internal_errors() and sapi_windows_vt100_support(). This aligns pcntl_signal() with them.

Runtime behaviour is unchanged: null was already accepted, and null and an omitted argument already took the same path. What changes is the declared signature, so Reflection now reports ?bool $restart_syscalls = null.

Fixes #23530

pcntl_signal() parses its third argument with Z_PARAM_BOOL_OR_NULL(), so
null is accepted, and null is also what selects the SIGALRM specific
default of false. The stub declared a non-nullable bool defaulting to
true, so Reflection reported a signature the implementation does not
honour.

Every other Z_PARAM_BOOL_OR_NULL() user declares a nullable parameter
defaulting to null: imageinterlace(), json_decode(),
libxml_use_internal_errors() and sapi_windows_vt100_support(). Align
pcntl_signal() with them.

Runtime behaviour is unchanged: null was already accepted, and null and
an omitted argument already took the same path.
@devnexen

devnexen commented Sep 1, 2026

Copy link
Copy Markdown
Member

fix is good but you might be able to test it with declare(strict_types=1) ?

…lls)

Covers the nullable third parameter under declare(strict_types=1): the
reflected type and default, null/true/false and the omitted argument, and
the TypeError raised for a non-bool.
Comment thread ext/pcntl/tests/pcntl_signal_restart_syscalls.phpt Outdated
Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pcntl_signal(): declared signature of $restart_syscalls does not match the implementation

3 participants