+ 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?
3 Antworten
+ 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
+ 2
Thank you Manos Manik
0
I have come back to my question just now. I know how namespaces work :)