Skip to content

Add zend_argument_type_error_ex, zend_argument_error_ex#21829

Open
arnaud-lb wants to merge 2 commits intophp:masterfrom
arnaud-lb:zend-error-ex
Open

Add zend_argument_type_error_ex, zend_argument_error_ex#21829
arnaud-lb wants to merge 2 commits intophp:masterfrom
arnaud-lb:zend-error-ex

Conversation

@arnaud-lb
Copy link
Copy Markdown
Member

@arnaud-lb arnaud-lb commented Apr 22, 2026

These variants take the function as parameter instead of inferring it from the call stack. This is useful in ZEND_TYPE_ASSERT, and will be used in PFA impl.

UPGRADING.INTERNALS:

  . Added zend_argument_error_ex(), zend_argument_type_error_ex()
  . zend_argument_error_variadic() now takes an additional `function` parameter

@arnaud-lb arnaud-lb marked this pull request as ready for review April 22, 2026 09:37
@arnaud-lb arnaud-lb requested a review from dstogov as a code owner April 22, 2026 09:37
@arnaud-lb arnaud-lb requested a review from TimWolla April 22, 2026 13:35
Copy link
Copy Markdown
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes a lot of sense :)

Copy link
Copy Markdown
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way LGTM, consider adding the new functions to UPGRADING.INTERNALS with a short note.

Comment thread Zend/zend_API.c
arnaud-lb added 2 commits May 6, 2026 11:25
These variants take the function as parameter instead of infering it from the
call stack. This is useful in ZEND_TYPE_ASSERT, and will be used in PFA impl.
Comment thread Zend/zend_API.c
Comment on lines +400 to +401
ZEND_API ZEND_COLD void zend_argument_error_ex(const zend_function *function,
uint32_t arg_num, zend_class_entry *error_ce, const char *format, ...)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only noticing now that error_ce and arg_num are flipped compared to the existing zend_argument_error(). That should be adjusted.

Suggested change
ZEND_API ZEND_COLD void zend_argument_error_ex(const zend_function *function,
uint32_t arg_num, zend_class_entry *error_ce, const char *format, ...)
ZEND_API ZEND_COLD void zend_argument_error_ex(const zend_function *function,
zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why? Is it to match the order of the non-_ex function?

function and arg_num are related, so grouping them would make sense.

Looking at other format-and-throw functions, extra args tend to be grouped in between ce and format:

zend_object *zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code);
zend_object *zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format, ...);
void ZEND_FASTCALL zend_argument_error_variadic(zend_class_entry *error_ce, uint32_t arg_num, const char *format, va_list va);

void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);

What do you think of this?

Suggested change
ZEND_API ZEND_COLD void zend_argument_error_ex(const zend_function *function,
uint32_t arg_num, zend_class_entry *error_ce, const char *format, ...)
ZEND_API ZEND_COLD void zend_argument_error_ex(zend_class_entry *error_ce,
const zend_function *function, uint32_t arg_num, const char *format, ...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it to match the order of the non-_ex function?

Yes, my motivation was making this consistent with the existing non-_ex zend_argument_error(). Changing the argument order of that one would would be too impactful, I feel. That's why I suggested adjusting the new functions for consistency with their direct sibling, rather than zend_throw_exception.

Comment thread ext/openssl/openssl.c

if (type == E_ERROR) {
zend_argument_error_variadic(zend_ce_value_error, arg_num, format, va);
zend_argument_error_variadic(zend_active_function(), arg_num, zend_ce_value_error, format, va);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_error_variadic(zend_active_function(), arg_num, zend_ce_value_error, format, va);
zend_argument_error_variadic(zend_active_function(), zend_ce_value_error, arg_num, format, va);

Comment thread Zend/zend_API.c
Comment on lines +377 to +379
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(
const zend_function *function, uint32_t arg_num,
zend_class_entry *error_ce, const char *format, va_list va)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(
const zend_function *function, uint32_t arg_num,
zend_class_entry *error_ce, const char *format, va_list va)
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(
const zend_function *function, zend_class_entry *error_ce,
uint32_t arg_num, const char *format, va_list va)

Comment thread Zend/zend_API.c
va_list va;

va_start(va, format);
zend_argument_error_variadic(function, arg_num, error_ce, format, va);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_error_variadic(function, arg_num, error_ce, format, va);
zend_argument_error_variadic(function, error_ce, arg_num, format, va);

Comment thread Zend/zend_API.c

va_start(va, format);
zend_argument_error_variadic(error_ce, arg_num, format, va);
zend_argument_error_variadic(function, arg_num, error_ce, format, va);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_error_variadic(function, arg_num, error_ce, format, va);
zend_argument_error_variadic(function, error_ce, arg_num, format, va);

Comment thread Zend/zend_API.c
va_list va;

va_start(va, format);
zend_argument_error_variadic(function, arg_num, zend_ce_type_error, format, va);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_error_variadic(function, arg_num, zend_ce_type_error, format, va);
zend_argument_error_variadic(function, zend_ce_type_error, arg_num, format, va);

Comment thread Zend/zend_API.c

va_start(va, format);
zend_argument_error_variadic(zend_ce_type_error, arg_num, format, va);
zend_argument_error_variadic(function, arg_num, zend_ce_type_error, format, va);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_error_variadic(function, arg_num, zend_ce_type_error, format, va);
zend_argument_error_variadic(function, zend_ce_type_error, arg_num, format, va);

Comment thread Zend/zend_API.c

va_start(va, format);
zend_argument_error_variadic(zend_ce_value_error, arg_num, format, va);
zend_argument_error_variadic(function, arg_num, zend_ce_value_error, format, va);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zend_argument_error_variadic(function, arg_num, zend_ce_value_error, format, va);
zend_argument_error_variadic(function, zend_ce_value_error, arg_num, format, va);

Comment thread Zend/zend_API.h
Comment on lines +1567 to +1576
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(
const zend_function *function, uint32_t arg_num,
zend_class_entry *error_ce, const char *format, va_list va);
ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_error_ex(const zend_function *function,
uint32_t arg_num, zend_class_entry *error_ce, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_type_error_ex(
const zend_function *function, uint32_t arg_num,
const char *format, ...);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(
const zend_function *function, uint32_t arg_num,
zend_class_entry *error_ce, const char *format, va_list va);
ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_error_ex(const zend_function *function,
uint32_t arg_num, zend_class_entry *error_ce, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_type_error_ex(
const zend_function *function, uint32_t arg_num,
const char *format, ...);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(
const zend_function *function, zend_class_entry *error_ce,
uint32_t arg_num, const char *format, va_list va);
ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_error_ex(const zend_function *function,
zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_type_error_ex(
const zend_function *function, uint32_t arg_num,
const char *format, ...);

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.

3 participants