On 03-09-2020 15:07, Larry Garfield wrote:
> 
> I agree here.  _ is already a common pattern in other languages for a 
> placeholder ignored variable.  It's not a big jump for PHP static analyzers 
> to start ignoring unused $_ variables, and it requires no language changes or 
> formal standards.
> 

Technically that will work. However, this needs to rely on some
unwritten undocumented convention that all of the user community agrees
on and is aware of. Such a convention can be established and documented
of course, it worked for doc comments as well.

Apparently the PHPMD project considered a change to recognize $_ as an
ignored variable. It was declined:

https://github.com/phpmd/phpmd/issues/326

In stead, configuration was added to allow specifying a variable name
that is to be ignored. Still, every individual user needs to manually
configure it and pick a name for ignored variables.

For one use case, using $_ simply does not appear to be an option, while
using void is. This is the use case of ignoring an argument that is
passed to a function:

  function foo($_) {}

This can work but it changes the name of the parameter. That is not the
intent at all. It breaks in inheritance scenarios. When it is called and
the parameter name is specified as the parent defines it, a fatal error
results.

What I like about using void is that it has clear intent, it requires no
configuration of static analyzers and it provides a single syntax that
works for all use cases: foreach, destructuring and function parameters.

Regards,
Dik Takken

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to