Once the outcome of a PHP method or procedure has been established, it SHOULD be returned. The examples below demonstrate this may save memory and computations.

Incorrect:

public function hasDownload()
{
    $download = false;
 
    foreach ($this->getProducts() as $product) {
        if ($product['download']) {
            $download = true;
            break;
        }
    }
 
    return $download;
}


Correct:

public function hasDownload()
{
    foreach ($this->getProducts() as $product) {
        if ($product['download']) {
            return true;
        }
    }
 
    return false;
}