Using PHP goto Labels for code folding I've been using PHP labels in my Controllers for code folding. PHP labels are actually used with goto statements. But I'm using labels only because it's so much easier to fold my code in different IDEs using labels + curly braces, and I can use labels as titles for different sections of the code.

Here's an example. Take a look at SettingCartFields label.

&lt;?php

namespace App\Http\Controllers;

use App\Cart;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class CartController extends Controller
{
    public function create(Request $request)
    {
        $cart = new Cart;

        SettingCartFields: {
            $cart-&gt;field1 = $request-&gt;field1;
            $cart-&gt;field2 = $request-&gt;field2;
            $cart-&gt;field3 = $request-&gt;field3;
            $cart-&gt;field4 = $request-&gt;field4;
            $cart-&gt;field5 = $request-&gt;field5;
            $cart-&gt;field6 = $request-&gt;field6;
        }

        $cart-&gt;save();
    }
}


I have a few questions, are there any performance issues with this? Am I introducing some kind of overhead by adding a lot of labels in my code? Is there any better way to do this?
The main issue I have with your approach is that it is non-standard and purely for the way that you work.  Others looking at your code may be a bit confused as to what you are doing and why.  In your example, there is (IMHO) little benefit in being able to fold the code as there is not really enough code to need to fold the code up, but in larger code segments there may be a use for it.

For me - it looks as though you are in the initial stages of identifying logically grouped functionality within your code, something that could then be extended by extracting these logical groups into new class methods.

The exact approach I would take depends on how much other processing you have with the cart either pre or post this main chunk of code.  

If there is a lot of other processing around what the cart does, then you could just pass the cart and the request to a new method and get something like...

class CartController extends Controller
{
    public function create(Request $request)
    {
        $cart = new Cart;

        $this-&gt;setCartFields ( $cart, $request );

        $cart-&gt;save();
    }

    private function setCartFields ( Cart $cart, Request $request ) {
        $cart-&gt;field1 = $request-&gt;field1;
        $cart-&gt;field2 = $request-&gt;field2;
        $cart-&gt;field3 = $request-&gt;field3;
        $cart-&gt;field4 = $request-&gt;field4;
        $cart-&gt;field5 = $request-&gt;field5;
        $cart-&gt;field6 = $request-&gt;field6;
    }
}


If the data from the request forms the basis of the data for the cart, then this could instead create it's own cart, initialise the data and return the newly created cart for further processing...

class CartController extends Controller
{
    public function create(Request $request)
    {

        $cart = createCart ( $request );

        $cart-&gt;save();
    }

    private function createCart ( Request $request ) : Cart {
        $cart = new Cart;
        $cart-&gt;field1 = $request-&gt;field1;
        $cart-&gt;field2 = $request-&gt;field2;
        $cart-&gt;field3 = $request-&gt;field3;
        $cart-&gt;field4 = $request-&gt;field4;
        $cart-&gt;field5 = $request-&gt;field5;
        $cart-&gt;field6 = $request-&gt;field6;

        return $cart;
    }

}


The problem being that you could eventually end up with all of the processing in the newly created method and rather than relieve the problem you have just moved it.  This is only something you can decide on a per instance basis.