Writing comments for Laravel functions with phpdoc requires to add classes. For example
/**
* Add item to cart and redirect back
*
* @return Response
*/
Automatically adds "\Illuminate\Http\Response" to the top of class like so:
namespace App\Http\Controllers;
use Illuminate\Http\Response;
class CartController extends Controller{
My question is: does it make it (at least a tiny bit) slower if I'm not using the class in the code (only in the comment)? Another option would be to write "@return \Illuminate\Http\Response" which does not include the class and since it's just a comment it shouldn't have any performance hit? Thanks a lot!
Technically it will not make a big difference. But if you're using PHP 7 or higher, you can mention return type in the code itself rather than in the comment. It'll help you, IDE, and the compiler to understand what to expect and your code will be protected from dynamic returns. So instead of doing,
/*
* @return Response
*/
public function index() {}
You can do,
public function index() : Response {}