note 76258 added to language.oop5.autoload
| From: | alexandre at nospam dot gaigalas dot net | Date: | Sun, 08 Jul 2007 05:33:19 +0000 |
| Subject: | note 76258 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128292@lists.php.net to get a copy of this message | ||
Here is a simple version of __autoload for creating custom classes on the fly, extending pre-defined
(using a constant) base classes:
<?php
define('CUSTOM_CLASS_TYPES', 'Application|Database|XML');
function __autoload($req) {
if (preg_match('#(.*)('.CUSTOM_CLASS_TYPES.'){1}$#', $req , $fragment))
eval('class '.$req.' extends base'.$fragment[2].' { public $_name =
\''.$fragment[1].'\'; public $_type = \''.$fragment[2].'\';
} ');
}
/* Base Classes */
class baseApplication {}
class baseDatabase {}
class baseXML{}
/* Calling a custom Class */
$foo = new projectApplication;
print_r($foo);
?>
----
Server IP: 200.185.109.13
Probable Submitter: 189.29.194.38
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit -- https://master.php.net/note/edit/76258
Del: integrated -- https://master.php.net/note/delete/76258/integrated
Del: useless -- https://master.php.net/note/delete/76258/useless
Del: bad code -- https://master.php.net/note/delete/76258/bad+code
Del: spam -- https://master.php.net/note/delete/76258/spam
Del: non-english -- https://master.php.net/note/delete/76258/non-english
Del: in docs -- https://master.php.net/note/delete/76258/in+docs
Del: other reasons-- https://master.php.net/note/delete/76258
Reject -- https://master.php.net/note/reject/76258
Search -- https://master.php.net/manage/user-notes.php