简体   繁体   English

PHP致命错误:无法在以下位置重新声明类AdminImportControllerCore

[英]PHP Fatal error: Cannot redeclare class AdminImportControllerCore in

I have a script with cURL to initiate other script that import products and categories in prestashop. 我有一个带cURL的脚本,可以启动其他脚本来导入prestashop中的产品和类别。

This is the script which start with cURL: 这是以cURL开头的脚本:

define('_PS_ADMIN_DIR_', getcwd());
include_once(_PS_ADMIN_DIR_.'/../config/config.inc.php');
include_once(_PS_ADMIN_DIR_.'/../config/defines.inc.php');
include_once(_PS_ADMIN_DIR_.'/functions.php');
include_once dirname(__FILE__).'/../controllers/admin/AdminImportController.php';

if (!isset($_GET['entity'])) die(); 

$import = New AdminImportController(); 
switch ($_GET['entity']) { 
case 0: 
    loadCategoriesPost(); 
    $import->categoryImport(); 
    break;

  case 1:
    loadProductsPost();
    $import->productImport();
    break;

}

My problem is that the seconds script generate an error from "include_once dirname( FILE ).'/../controllers/admin/AdminImportController.php';": 我的问题是秒脚本从“ include_once dirname( FILE )。'/ .. / controllers / admin / Admin / AdminImportController.php';”产生错误:

PHP Fatal error: Cannot redeclare class AdminImportControllerCore in... PHP致命错误:无法在...中重新声明类AdminImportControllerCore。

I have tried to use include_once, DIR , also I looked for in that included files a line with "new AdminImportController();" 我尝试使用include_once, DIR ,我也在包含文件中寻找了一个带有“ new AdminImportController();”的行。 but I don't found nothing. 但我什么也没发现。

Thanks! 谢谢!

Look inside the AdminImportController.php file. 查看AdminImportController.php文件的内部。 My guess is that it is also including the file that defines the AdminImportControllerCore class, and that it is not using the include_once verity of the include functions. 我的猜测是, 也包括定义文件AdminImportControllerCore类,而且它没有使用include_once真理的包括功能。

That would mean that your main page is defining the class through the include_once call, and then when it includes the AdminImportController class, the include there kicks in and tries to re-define the core class, with the results you described. 这意味着您的主页正在通过include_once调用定义该类,然后当它包含AdminImportController类时,其中的include将启动,并尝试使用您描述的结果重新定义核心类。

I suggest you look into PHP's autoloader feature . 我建议您研究一下PHP的自动加载器功能 It'll save you all the headaches associated with manually including files like that. 这样可以避免与手动包含此类文件有关的所有麻烦。 It also tends to promote good file and class naming practices. 它还倾向于促进良好的文件和类命名惯例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM