@@ -87,10 +87,13 @@ static BOOL WINAPI php_win32_signal_system_ctrl_handler(DWORD evt)
8787/* {{{ Assigns a CTRL signal handler to a PHP function */
8888PHP_FUNCTION (sapi_windows_set_ctrl_handler )
8989{
90- zval * handler = NULL ;
90+ zend_fcall_info fci ;
91+ zend_fcall_info_cache fcc ;
9192 zend_bool add = 1 ;
9293
93- if (zend_parse_parameters (ZEND_NUM_ARGS (), "z|b" , & handler , & add ) == FAILURE ) {
94+
95+ /* callable argument corresponds to the CTRL handler */
96+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "f!|b" , & fci , & fcc , & add ) == FAILURE ) {
9497 RETURN_THROWS ();
9598 }
9699
@@ -106,8 +109,7 @@ PHP_FUNCTION(sapi_windows_set_ctrl_handler)
106109 RETURN_THROWS ();
107110 }
108111
109-
110- if (IS_NULL == Z_TYPE_P (handler )) {
112+ if (!ZEND_FCI_INITIALIZED (fci )) {
111113 zval_dtor (& ctrl_handler );
112114 ZVAL_UNDEF (& ctrl_handler );
113115 if (!SetConsoleCtrlHandler (NULL , add )) {
@@ -116,20 +118,15 @@ PHP_FUNCTION(sapi_windows_set_ctrl_handler)
116118 RETURN_TRUE ;
117119 }
118120
119- if (!zend_is_callable (handler , 0 , NULL )) {
120- zend_argument_type_error (1 , "must be a valid callable function name" );
121- RETURN_THROWS ();
122- }
123-
124121 if (!SetConsoleCtrlHandler (NULL , FALSE) || !SetConsoleCtrlHandler (php_win32_signal_system_ctrl_handler , add )) {
125- zend_string * func_name = zend_get_callable_name (handler );
122+ zend_string * func_name = zend_get_callable_name (& fci . function_name );
126123 php_error_docref (NULL , E_WARNING , "Unable to attach %s as a CTRL handler" , ZSTR_VAL (func_name ));
127124 zend_string_release_ex (func_name , 0 );
128125 RETURN_FALSE ;
129126 }
130127
131128 zval_dtor (& ctrl_handler );
132- ZVAL_COPY (& ctrl_handler , handler );
129+ ZVAL_COPY (& ctrl_handler , & fci . function_name );
133130
134131 RETURN_TRUE ;
135132}/*}}}*/
0 commit comments