Search code examples
phpyiicurly-bracescurly-brackets

PHP - Lock-contentions with curly braces?


One of my colleagues wrote this worker class (used in Yii 1.1/Pheanstalk).

In code review I stumbled upon the two blocks of curly braces and ask him why he did it this way. He said he wants to prevent lock-contentions.

I've never heard about it before! Is it really working this way?

class InvoiceWorker
{
    public static function generateAndSendInvoice($id)
    {
        // some code

        {
            $order = Order::loadLocked(new MongoId($id));
            Yii::app()->invoiceManager->createInvoice($order);
        }

        {
            $order = Util::safeFindByPk("Order", new MongoId($id));
            Yii::app()->invoiceManager->sendMail($order);
        }

        // some more code
    }
}

Solution

  • No, the curly braces have absolutely no effect on whatever your colleague meant by saying "lock contentions".