Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
private function _compareHashes($hash1, $hash2)
{
return $hash1 == $hash2;
}
private function _compareHashes($hash1, $hash2)
{
return $hash1 == $hash2 ? true : false;
}
private function _compareHashes($hash1, $hash2)
{
if ($hash1 == $hash2)
{
return true;
}
return false;
}
I've been using the first one a lot lately, using operators to be evaluated in the return statement. I'm unaware of if this is practiced a lot, or if it could potentially cause anything different than an if{} statement.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
It all seriously depends on your personal preference and readability. I would lean towards the first example though.. although I usually wrap my expressions in brackets.
Jcart wrote:It all seriously depends on your personal preference and readability. I would lean towards the first example though.. although I usually wrap my expressions in brackets.
Any reason for that codewise? Or just readability?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Technically, it would be the most likely to have the least number of opcodes thereby executing a fraction of a second faster, depending on how efficient the opcode optimizer is.
They are all identical to the code that calls the function. The question then becomes which is the most readable, consistent and maintainable considering the rest of your codebase.
The first would be my preference as well -- mainly for readability. With it I can see most clearly what is being returned. The others require scanning multiple lines or operators.