Re: hubzilla legacy code (files module)
[email protected] (AllenJB)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
On 01/09/2021 19:33, ourdiaspora wrote: > Line 8 refers to another file with the key word 'use', but a user > contributor comment to the php manual > (https://www.php.net/manual/en/language.namespaces.php) states there > are two possible applications? `use` (in this case) refers not (directly) to a filename or path, but a namespace. In the vast majority of cases, you'll find these are set up using Composer's built-in autoloader, so checking the project composer.json will give you the "root" of the namespace. From there you can basically follow the directory structure. This behavior is defined in PSR-4: https://www.php-fig.org/psr/psr-4/ You can read more on autoloading in the manual: https://www.php.net/manual/en/language.oop5.autoload.php It's possible to specify custom autoloading schemas, and Composer supports other autoloading methods ( https://getcomposer.org/doc/04-schema.md#autoload ) but PSR-4 is by far the most common. The other place you'll see the `use` keyword used is with anonymous functions to inherit variables from the parent scope: https://www.php.net/manual/en/functions.anonymous.php#example-163 The 2 usages are quite distinct and not easy to confuse (the former is almost always at the top of the file, the latter is always in a function declaration) > Line 6 of the next file (https://framagit.org/hubzilla/core/-/blob/master/Zotlabs/Lib/Libsync.php) refers to keyword 'use' some object 'App'; where to find that??? The class `App` has been defined in the `boot.php` file in the root of the project: https://framagit.org/hubzilla/core/-/blob/master/boot.php (Since the `App` class is in the root (`\`) namespace I found it by starting from the "index.php" in the project root and found the boot.php included by Zotlabs\Web\Webserver)