Page 1 of 1

Fatal error when including a external PEAR class-file!

Posted: Thu Sep 29, 2005 2:34 am
by dma147
Hello Garvin, hello s9y-team,

As you poperly know, I'm just writing this backup-plugin, which provides automatic backup-functions for backupping the whole s9y file-structure, the database or only some database-tables.

This plugin needs some include_once("Archive/Tar.php"); to pack the sql-backup into .tar.gz.
This all works quiet well with serendipity-0.8.4, but I've updated to 0.9-alpha5 today and since this update the plugin complains the following, when including "Archive/Tar.php":

Fatal error: Cannot redeclare class pear in /usr/share/php/PEAR.php on line 73

This seems to be caused by the require_once() functions, which you are using to include the pear classes in the bundled-libs directory, because require_once results in a fatal error, when it fails.
Maybe you should replace these require_once() to include_once(). Then there should be no problem anymore with already declared pear classes.

I'll try this with my s9y and will report the succes or even the failure.

[edit]
Hmm... it seems that only a few plugins uses require_once to include files from the bundled-libs directory...
Well, I'll try to replace them anyway...
[/edit]

Posted: Thu Sep 29, 2005 3:17 am
by dma147
well, okay, this doesn't change anything... :(
Any other ideas?

Posted: Thu Sep 29, 2005 2:39 pm
by garvinhicking
If you require PEAR files that are not bundled, those PEAR classes need to check if a PEAR class is already defined, and not just use include_once for the PEAR.php file.

The reason is that s9y provides its own pear.php file, and of course an include_once will include a different file of your local Server.

You have three options:

1. Tell the ARchive/Tar maintainers to fix their PEAR class to not rely on file names but on class declarations.

2. Bundle the Archive/Tar file with your plugin and fix that TAR.php PEAR inclusion call.

3. Turn on your "use_PEAR" serendipity configuration item inside serendipity_config_local.inc.php: $serendipity['use_PEAR'] = true;

However then your plugin will only work if other people also switch this setting. And if you use option 2, you will need to maintain your own version of TAR.php.

So the only real way is to go with 1. :-)

Regards,
Garvin

Posted: Thu Sep 29, 2005 2:44 pm
by dma147
Thanks Garvin for the answer...

I think I'll choose point 2, because this also prevents from old Tar.php, because they have a really heavy bug which causes to let the created tar.gz file grow until the harddisc is full...