Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jwavess's avatar

I'm trying to figure out what namespacing is

Here are my notes, let me know if Im close!

Okay, lets talk about name spacing. Name spacing is a way of using a files content in another file. Lets say you have a model named “dogs” in the project path of App/dogs. Go inside the file you want to use the model in, and at the top of that file, simply type "use App/dogs". Whenever you are inside a file and you see “use” followed by a path, that means this namespace is “using” those other namespaces content. The “namespace” of a file is its path to “use” in another file .?!

When you “use” a files namespace, you can call that files content. Such as a class name, object, etc

Seth

0 likes
2 replies
lara25260's avatar
Level 5

Namespace is another way of using raw "includes" except now we have a named way of using it.

Use App/Dogs;

Would name all "new Dogs" as a PHP file names Dogs under App.

Use App/Cats as Dogs;

Now we call a cats class under the app directory except all "new Dogs" now use the cats class PHP file.

As you can see, it allows easier switching of files.

1 like
jwavess's avatar

@CrushCandy Awesome, yea I just finally got a hold on namespacing, typing thing and what the :: and -> where in Laravel. I forgot that you can access your query builder directly in the code. So when I saw the :: and -> I was getting super confused.

Seth

Please or to participate in this conversation.