Skip to content

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Nov 9, 2020

We assert that retval IS_UNDEF if call_user_function(), to catch
a potentially uninitialized retval. This might also help static code
analyzers to avoid raising false positives.


I don't see any issues with the current code, but still it might be a good idea to assert this condition. Probably PHP-8.0 or the "master" branch would be more appropriate targets for this change.

We assert that `retval` `IS_UNDEF` if `call_user_function()`, to catch
a potentially uninitialized `retval`.  This might also help static code
analyzers to avoid raising false positives.
@nikic
Copy link
Member

nikic commented Nov 9, 2020

I don't think this change makes sense. This is just asserting the contract of the function.

Longer term, we should probably make call_user_function() effectively infallible, by throwing if the function cannot be called.

@cmb69
Copy link
Member Author

cmb69 commented Nov 9, 2020

I think we should at least document such contracts by adding respective comments, since there appears to be some confusion, e.g. no need to ZVAL_FALSE(&retval) here:

ZVAL_FALSE(&retval);
if (description_str) {
ZVAL_STR(&args[3], description_str);
call_user_function(NULL, NULL, &ASSERTG(callback), &retval, 4, args);
} else {
call_user_function(NULL, NULL, &ASSERTG(callback), &retval, 3, args);
}
zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&retval);

Making _call_user_function_impl() infallible is fine for me; or maybe add assertions to the function?

@ramsey ramsey added the Bug label Jun 9, 2021
@krakjoe
Copy link
Member

krakjoe commented Aug 31, 2025

Closing this, it was opened against a branch we no longer support a very long time ago.

There was some confusion/disagreement about whether the change is worth it, or correct.

If you'd like to revisit the topic, please open a pull against a supported branch.

On a side note, it never really looked necessary to me to make any change, you should check the return value of zend_call_function, when you need too; if it makes no difference what the return value is in the branch that called it, then it looks like a pointless additional branch to me.

@krakjoe krakjoe closed this Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants