PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 7, 2022

[FIXED] Any difference between this 2 ways to use a class in PHP?

 March 07, 2022     laravel, php     No comments   

Issue

Currently developing a Laravel app and a question came to mind. Is any "technical" difference between this two ways to use a class?

First way:

public function store() {
    new \Illuminate\Auth\Events\Registered($user)
}

VS

Second way:

use Illuminate\Auth\Events\Registered;

public function store() {
    new Registered($user)
}
  1. One way is more performant than the other?
  2. Is any difference in the way PHP reads this lines?
  3. When the class is only used once, is better to include it using first way or second way?
  4. Also any other this than comes to mind...

Solution

No difference in performance but its personal choice but if you are using the class more than once in the same class importing once works well and looks clean in my view



Answered By - Nishan Timsina
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing