“Fatal error: Cannot redeclare class” … but the class was not declared

余生长醉 提交于 2019-12-10 16:13:08

问题


(I'm using Joomla v1.5.15 and PHP 5.3.4)

I have tested the solutions found in this and others developer forums, but I still having the same error.

Requiring file => contratolocal.php

...
if ( !class_exists('MTIHelperEstadosLocal') )
    JLoader::import('helpers.estados.estadoslocal', JPATH_COMPONENT, false);

class MTIControllerContratoLocal extends MTIController
{
...

Required file => estadoslocal.php

...
class MTIHelperEstadosLocal extends MTIHelperEstados
{
...

"JLoader::import" is used normally in Joomla to import files to the actual script. Anyway, I tried "include/require_once" php methods also without success.

I got the same error with every solution that I tried:

"Fatal error: Cannot redeclare class MTIHelperEstadosLocal"

The class is not declarated previously becouse I can't use the class without the import and if I print the returned array of the "get_declared_classes()" php method, this class isn't there.

What going on?

Thanks


回答1:


Solved.

There were 2 problems:

  1. In my project there are some helpers that include other files, and one of them has a require_once previously done.
  2. The require_once doesn't avoid the second include, and I had to code every require_once in a condition:

    if ( !class_exists('MTIHelperEstadosLocal') )



来源:https://stackoverflow.com/questions/8668630/fatal-error-cannot-redeclare-class-but-the-class-was-not-declared

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!