note 126086 added to language.oop5.autoload
| From: | LaHongHai at main dot php dot net | Date: | Wed, 19 May 2021 00:12:59 +0000 |
| Subject: | note 126086 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216395@lists.php.net to get a copy of this message | ||
I use namespaces that match the files' directory paths (root excluded) so all i have to do with
spl_autoload_register is:
<?php
spl_autoload_register(function (string $class): void {
require "{$_SERVER['DOCUMENT_ROOT']}\{$class}.php";
}
);
?>
No matter how complex your directory path is, there's no need for recursion or searching the
whole project.
*You might want to use str_replace() to replace "\" to "/" if you're using
Linux (untested)
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 183.77.231.22)
----
Manual Page -- https://php.net/manual/en/language.oop5.autoload.php
Edit -- https://main.php.net/note/edit/126086
Del: integrated -- https://main.php.net/note/delete/126086/integrated
Del: useless -- https://main.php.net/note/delete/126086/useless
Del: bad code -- https://main.php.net/note/delete/126086/bad+code
Del: spam -- https://main.php.net/note/delete/126086/spam
Del: non-english -- https://main.php.net/note/delete/126086/non-english
Del: in docs -- https://main.php.net/note/delete/126086/in+docs
Del: other reasons-- https://main.php.net/note/delete/126086
Reject -- https://main.php.net/note/reject/126086
Search -- https://main.php.net/manage/user-notes.php