When to use `use` or the fully qualified name

Viewed 1087

I'm wondering when to use the fully qualified class name or when to put a use statement on top of the class. For example:

namespace App;

use Illuminate\Database\Eloquent\Model;

class ImageStatus extends Model {
    public function image(): \Illuminate\Database\Eloquent\Relations\BelongsTo {
        return $this->belongsTo( \App\Image::class, 'id' );
    }

    public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo {
        return $this->belongsTo( \App\User::class, 'id' );
    }
}

At the moment I have this piece of code and my PHPStorm tells me Unnecessary fully qualified name. This hint disappears when I change it to:

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ImageStatus extends Model {
    public function image(): BelongsTo {
        return $this->belongsTo( \App\Image::class, 'id' );
    }

    public function user(): BelongsTo {
        return $this->belongsTo( \App\User::class, 'id' );
    }
}

So I'm wondering what the difference is, performance wise, code readability and if one is better than the other.

1 Answers
Related