+ 2

Php Namespaces, what are they?

Hi guys. Im learning laravel and I dont understand some core php practices so perhaps you can help me understand namespacing. I know that at the top of my controllers i import like so: use App\User; but for the vendor folders that are referenced like that without an absolute path, that I dont understand. How does the php class im writing know where the classes Im including are based on a relative path?

5th Feb 2020, 3:14 AM
⊹≒tɧε8шσσɖɕนttεг≓⊹
⊹≒tɧε8шσσɖɕนttεг≓⊹ - avatar
3 Answers
+ 6
Namespaces are a way of encapsulating items.  Namespaces are designed to solve two problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions: 1.Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants. 2.Ability to alias (or shorten) Extra_Long_Names designed to alleviate the first problem, improving readability of source code. PHP Namespaces provide a way in which to group related classes, interfaces, functions and constants. You can find more info and examples about namespaces here: https://www.php.net/manual/en/language.namespaces.rationale.php https://www.php.net/manual/en/language.namespaces.php
11th Feb 2020, 11:37 PM
Manos Manik
Manos Manik - avatar
+ 2
Thank you Manos Manik
15th Feb 2020, 2:35 AM
⊹≒tɧε8шσσɖɕนttεг≓⊹
⊹≒tɧε8шσσɖɕนttεг≓⊹ - avatar
0
I have come back to my question just now. I know how namespaces work :)
6th Dec 2020, 9:16 AM
⊹≒tɧε8шσσɖɕนttεг≓⊹
⊹≒tɧε8шσσɖɕนttεг≓⊹ - avatar