note 80854 deleted from language.oop5.autoload by felipe
| From: | felipe@php.net | Date: | Mon, 24 Mar 2008 22:39:40 +0000 |
| Subject: | note 80854 deleted from language.oop5.autoload by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137501@lists.php.net to get a copy of this message | ||
Note Submitter: matt at frederation dot com
----
@ 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.