* Thus wrote Ed Lazor:
> I'm creating classes that rely on the presence of other classes that I've
> created. Does PHP5 provide a way to specify these dependencies or a way to
> check these dependencies when the class is instantiated? For example, class
> Automobile would fail to instantiate if class Tire wasn't available.
>
> I know the __autoload feature of PHP5 could be used to flag an error like
> this:
>
> function __autoload($class_name) {
> if ([EMAIL PROTECTED]("$class_name.php")) {
> echo "Error: Unable to load $class_name.<br>";
> }
> }
What you can do is something like this:
function __autoload($class_name) {
static $_stack = array();
// push the calls of autoload here
array_push($_stack, $class_name);
if ( [EMAIL PROTECTED]("$class_name.php") ||
!class_exists($class_name, false) ) {
var_dump($_stack);
$_stack = array(); // reset it
echo "Error: Unable to load $class_name.<br>";
return false;
}
// pop the stack
array_pop($_stack);
return true;
}
Curt
--
The above comments may offend you. flame at will.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php