On 29 January 2025 22:48:03 GMT, Christian Schneider <[email protected]> wrote:
>I think the (void) cast is familiar for people from C or the like, the only caveat is that it is
>not backward compatible, i.e. code using it won't work on older versions of PHP so migrating to
>it is not seamless, so it probably should not be used for a while in public libraries / packages.
I suspect that a majority of PHP users will probably have had no experience in C, which is easy to
forget on this list where we're working on a C codebase. In C, "void" has various
uses in the type system, but in PHP this would effectively just be a specific keyword for this case.
I think it would be good to explore alternatives - for instance, I think C# has a reserved _
variable to assign discarded results to, but may be misremembering.
>but my question is whether $_ = outer() and nop(outer()) will be guaranteed to not being
>optimized in a way which causes the warning to reappear. I don't know much about the
>optimizations being done but this could be an issue in the future, no?
I second this concern: having code that you think has suppressed the warning later be optimized and
start warning could be very confusing, and given the backwards compatibility issue, users will need
something other than "(void)" which is reliable.
My other thought reading the proposal is that if this can be done efficiently, can we use the same
approach to warn when a "void" function's return *is* used?
Regards,
Rowan Tommins
[IMSoP]