What is the difference between accessing the class through "use" keyword or declaring it as "new" plus the filepath of the class?
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
//if accessed using use keyword
use App\Entity\User;
class SampleController extends Controller
{
public function add(Request $request)
{
//if declared by "use" keyword above
$user = new User();
//if not declared by "use" keyword
$user = new \App\Entity\User();
}
}
If I'm going to use the functions of User
class, the results are the same but what's the difference in their declarations?