What labels?
Dec 16, 2019
7
Level 2
Using PHP goto Labels for code folding
Hi,
Lately, 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.
Here's an example.
<?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->field1 = $request->field1;
$cart->field2 = $request->field2;
$cart->field3 = $request->field3;
$cart->field4 = $request->field4;
$cart->field5 = $request->field5;
$cart->field6 = $request->field6;
}
$cart->save();
}
}
I have a few questions, are there any performance issues with this? Am I adding some kind of overhead by introducing a lot of labels in my code? Is there any better way to do this?
Please or to participate in this conversation.
