note 80854 added to language.oop5.autoload
| From: | matt at frederation dot com | Date: | Mon, 04 Feb 2008 12:20:16 +0000 |
| Subject: | note 80854 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135757@lists.php.net to get a copy of this message | ||
@ richard [at ] xanox [dot] net:
Your script does not take into consideration load order or constructor paramenters! Better to not
use this method, instead opting for a static array in which you may specify your constructor params.
Something like:
<?php
$requiredClasses = array('database' => false,
'settings' => true,
'scorekeeper' => null,
'userData' => $currentUser,
'wordCache' => null,
'heuristics' => $currentUser,
'spellChecker' => null,
'wordHandler' => $_POST['thePhrase'],
'reporter' => null,
'formBuilder' => null,
'advertServer' => null,
'templateParser' => null,
'userInteraction' => null
);
foreach ($requiredClasses as $class => $constructorParams) {
require_once($applicationBaseURL .'client/'. $class .'.class.php');
if (!is_array($constructorParams)) {
$$class = new $class($constructorParams);
} else {
foreach ($constructorParams as $param) {
$params .= '"'. $param .'",';
}
$$class = new $class(substr($params, 0, -1));
}
if (!$$class instanceof $class) {
throw new Exception("No instance of ". $class ." available");
}
}
?>
This, I find, works well.
----
Server IP: 87.124.64.96
Probable Submitter: 195.188.203.53
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit -- https://master.php.net/note/edit/80854
Del: integrated -- https://master.php.net/note/delete/80854/integrated
Del: useless -- https://master.php.net/note/delete/80854/useless
Del: bad code -- https://master.php.net/note/delete/80854/bad+code
Del: spam -- https://master.php.net/note/delete/80854/spam
Del: non-english -- https://master.php.net/note/delete/80854/non-english
Del: in docs -- https://master.php.net/note/delete/80854/in+docs
Del: other reasons-- https://master.php.net/note/delete/80854
Reject -- https://master.php.net/note/reject/80854
Search -- https://master.php.net/manage/user-notes.php