note 49496 added to language.oop5.autoload

From: Date: Sun, 30 Jan 2005 09:27:29 +0000
Subject: note 49496 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-84195@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49496 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49496&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49496&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49496&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49496&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49496&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49496&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84195) next »