Error: Cannot redeclare class POG_Base

95 views
Skip to first unread message

emi_c

unread,
Nov 3, 2011, 5:21:48 PM11/3/11
to Php Object Generator
Hello,
I'm trying this wonderful code generator and I have an error message
when I submit a form:

Fatal error: Cannot redeclare class POG_Base in C:\xampp\htdocs\HyH
\Admin\whitelabelTheme\ARCHIVOS\include\objects\class.pog_base.php on
line 3

I don't know how to solve it... if anyone could help me I would
appreciate that
Thanks in advance.
emi_c

Mario

unread,
Nov 4, 2011, 3:33:10 AM11/4/11
to php-object...@googlegroups.com
Hello Emi, (I guess this is your name, sorry if not)
    make sure you are using include_once or require_once of "class.pog_base.php",
instead of just include or require. It seems you have made two includes of that file,
or you have two different "class.pog_base.php" files. Check it. Make sure all your
pog objects are in the same directory. If you don't find where you are including the first
pog_base class you can patch your "C:\xampp\htdocs\HyH
\Admin\whitelabelTheme\ARCHIVOS\include\objects\class.pog_base.php" file declaring
the pog_class inside a check like this one:


C:\xampp\htdocs\HyH
\Admin\whitelabelTheme\ARCHIVOS\include\objects\class.pog_base.php
===========
<?php
if (!class_exists('POG_Base')){
// /* then the original code*/ //
}//close the if at the end of the file
-----------------------------
You may conside using something such as an autoLoader like the one I attach below,
so you don't need to use in your code more includes than the configuration.php file,
and this autoloader.php file.

Have a nice day!
autoloader.php
===========
<?php
function autoLoader($className)
{
$directories = array(
realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR,
realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR)
);
$fileNameFormats = array('class.%s.php', '%s.php', '%s.class.php', '%s.inc.php');
foreach($directories as $directory)
{
foreach($fileNameFormats as $fileNameFormat)
{
  $path = $directory.sprintf($fileNameFormat, $className);
  if(file_exists($path))
{
include_once $path;
return;
  }
}
}
$className = strtolower($className);
foreach($directories as $directory)
{
foreach($fileNameFormats as $fileNameFormat)
{
  $path = $directory.sprintf($fileNameFormat, $className);
  if(file_exists($path))
{
include_once $path;
return;
  }
}
}
}
spl_autoload_register('autoLoader');

Reply all
Reply to author
Forward
0 new messages