在这种情况下不使用变量名是一个好习惯吗? [关闭]

Is this really an standard?, I couldn't find any information around

"not assigning a value to a variable that will be used immediately and in only place"

For example, is this better:

$isHuman = true; // or false
$entity = new Something();
$this->whatever($something, $isHuman);

Than this:

$entity = new Something();
$this->whatever($something, true); // is prefeareable to use "true/false" directly?

If code is not optimized at compile/run time, an extra variable that isn't being used is theoretically wasted allocation and clean up. In such a simple implementation I believe readability is most important. In your case, that could be handled via a comment rather than a named variable (which does actually help with the readability on that line).

If the variable is not going to ever be conditionally reassigned, I would say that you shouldn't create a variable. Reading the first example without context makes me feel as if that variable was meant to be conditionally assigned somewhere, and it's confusing there is no place where that's possible.