Welcome to Geeklog Saturday, September 19 2020 @ 08:27 am EDT

Geeklog Forums

Coding Conflict


Anonymous

Anonymous
I'm working on an enhanced database backup plugin. I changed it from a hack to a plugin which was an experience in itself. Rather than loading all the code upfront initially, I load the alternate backup portion (which is much longer) only if the user selects this option. There are two submit buttons -- one for the main backup (which is the current routine and uses mysqldump) and one for the alternate. When I do a conditional include_once for the alternate, I receive the following error message: Fatal error: Cannot redeclare store_temp() (previously declared in /var/www/html/weather/phpweather.inc:22) in /var/www/html/weather/phpweather.inc on line 22 This problem is caused because the weather block is using "include" vice "include_once" in display_weather.php and array.php. When changed to include_once, everything works okay. I don't have all the blocks installed on my system. So, I don't know if there's a similar conflict with other ones. The utility works fine with all the standard blocks that come with Geeklog. Question: Is the onus on block/plugin writers to use include_once and require_once (like the new plugin manual says) or should we not use conditional includes? I don't know if I should rework my code in case some other block used include and require instead of include_once and require_once or let people test it out and see if any other blocks are affected and let the other developers change how they include files.
 Quote

Anonymous

Anonymous
The problem is not with your include/require statements but you have a naming collision. On line 22 of phpweather.inc is the delaration of a function called store_temp(). Either you have a function with the same name or you reincluded lib-common which should not be necessary. TomW
 Quote

Anonymous

Anonymous
I have no functions by that name, and I use require_once for lib-common in mine. When I changed the weather block from include to include_once, the problem disappears. I've decided to just go ahead and modify mine not to do conditional includes to avoid hitting this error in possibly other block scripts that use the plain include and require.
 Quote

All times are EDT. The time is now 08:27 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content