Skip to content

Add (void) cast - #18115

Merged
ndossche merged 2 commits into
php:masterfrom
TimWolla:void-cast
Mar 24, 2025
Merged

Add (void) cast#18115
ndossche merged 2 commits into
php:masterfrom
TimWolla:void-cast

Conversation

@TimWolla

Copy link
Copy Markdown
Member

RFC: https://wiki.php.net/rfc/marking_return_value_as_important

Spun out of #17599, since the (void) cast implementation is fully independent of the #[\NoDiscard] implementation and sufficiently complex on its own, allowing for an easier review.

Comment threadZend/zend_compile.c Outdated
@TimWolla
TimWolla requested a review from ndosscheMarch 21, 2025 08:22
Comment threadZend/zend_vm_def.h Outdated
Comment threadZend/zend_compile.c Outdated

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 guess you could optimize it a bit by not even handling IS_CONSTANT_AST in the first place, i.e. early returning.
I would still keep the IS_CONST handling below though because it generalises.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

As with the (void)(bool) cast, this feels like needless added complexity for a case that is unlikely to happen in practice and also no longer matters once the file is compiled and OPcached.

Comment threadZend/zend_compile.c Outdated
Comment threadZend/Optimizer/block_pass.c Outdated

@iluuu1994iluuu1994 left a comment

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.

This is missing support for AST printing in zend_ast.c.

LGTM otherwise.

Comment threadZend/tests/type_casts/cast_to_void_statement.phpt Outdated
Sign up for freeto 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

@TimWolla@iluuu1994@ndossche