doulan8054 2013-07-04 01:04
浏览 44
已采纳

PHP致命错误:无法重新声明类AdminImportControllerCore

I have a script with cURL to initiate other script that import products and categories in prestashop.

This is the script which start with 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';":

PHP Fatal error: Cannot redeclare class AdminImportControllerCore in...

I have tried to use include_once, DIR, also I looked for in that included files a line with "new AdminImportController();" but I don't found nothing.

Thanks!

  • 写回答

1条回答 默认 最新

  • dsf5989 2013-07-04 01:48
    关注

    Look inside the AdminImportController.php file. 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.

    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.

    I suggest you look into PHP's autoloader feature. 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等