note 49496 deleted from language.oop5.autoload by crell
| From: | crell@php.net | Date: | Mon, 04 Apr 2022 16:08:41 +0000 |
| Subject: | note 49496 deleted from language.oop5.autoload by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218023@lists.php.net to get a copy of this message | ||
Note Submitter: petyo()architect . bg
----
The following function may be useful if you want to simulate namespaces and autoloading behavior:
define ("CLASS_ROOT", '/classes/');
function __autoload ($className)
{
require_once CLASS_ROOT.str_replace('_', '/',
$className).'.class.php';
}
Then you will just have to use the folder structure and name the classes accordingly. If you want to
have a class named Page, which will be in the pseudo namespace System.Web.UI, create a directory
named System in /classes, then create Web, then UI, then name the class System_Web_UI_Page. Kind of
long to type if you don't have autocomplete, but at least you will not have to manage the
loading of all the classes' definitions.