我有父母和子女班。当我启动子类时,将触发父构造函数。 我已经为我的子类添加了一个空构造函数来绕过它,但没有运气。父构造函数仍然被触发,这会产生超时错误。
class modules {
public function __construct() {
global $Analytics;
//get active modules and add to $modules
if (is_dir(DIR_FS_CATALOG.$this->modules_folder)) {
$dirHandle = opendir(DIR_FS_CATALOG.$this->modules_folder);
while(false !== ($module = readdir($dirHandle))) {
if (is_dir(DIR_FS_CATALOG.$this->modules_folder.$module) && $module != '.' && $module != '..') {
//Find the class
$object = glob(DIR_FS_CATALOG.$this->modules_folder.$module.'/*_module.php');
//Include the class
require_once($object[0]);
//log every step
$Analytics->abo_analytics_add_action('file', $object[0], 'include');
//Prepare the variable
$object = str_replace(DIR_FS_CATALOG.$this->modules_folder.$module.'/', "", $object[0]);
$object = str_replace('.php', '', $object);
//remove '_module'
$class = str_replace('_module', '', $object);
//initiate modules class if not registered yet
if (!tep_session_is_registered($class) || !is_object($$class)) {
global $$class;
$$class = new $class;
//log every step
$Analytics->abo_analytics_add_action('class', $class, 'initiate');
//sort by sort order in modules by type
$this->modules[$$class->type][$$class->sort_order] = $class;
//log every step
$Analytics->abo_analytics_add_action('checkout', $class, 'add to modules', $$class);
tep_session_register($class);
}
}
}
} else {
//abo_error_message("<span style='color:#FF0000;'>[CHECKOUT MODULES]</span> The specified Module Folder, " . DIR_FS_CATALOG.$this->modules_folder . " does not exist or isn't accesible." );
}
}
...
}
class checkout extends modules {
public function __construct() {
echo 'test';
}
}
$modules = new modules();
$checkout = new checkout();
我该如何解决这个问题? 也很高兴知道。对象'modules'用作不同其他对象的父对象,而不仅仅是'checkout'。当我将构造函数添加到'checkout'对象时,我只有错误。当我在checkout中删除构造函数时,一切正常,但我的'modules'对象再次启动。