PHP Fatal error: Cannot unset string offsets in GalleryUtilities.class

algurgazan

Joined: 2007-02-22
Posts: 5
Posted: Thu, 2009-01-01 22:55

For some reason my gallery isn't working like it should in my embedded environment... It's embedded in a CMS called subdreamer through a lousy plugin I had to tinker with to get it started, and it worked just fine.. I got some (unrelated) problems with permissions and had to reinstall, and now I've run into another problem: when I'm logged in in the CMS (which goes through SMF btw, but i don't think that matters to gallery 'cause it has nothing to do with it, goes through the CMS first) gallery gets PHP to throw the error in the subject:

PHP Fatal error: Cannot unset string offsets in ///public_html/gallery2/modules/core/classes/GalleryUtilities.class on line 387

Strange thing is that it doens't happen all the time, and that it happens the most (but not always) when a user is logged in, and doesn't seem to happen when not logged in.. It also doesn't happen when the gallery is accessed directly..

Site url: http://solagratiazeist.nl
Gallery version 2.3
PHP version 5.2.8
Webserver Apache 2.2.11
Database MySql 5.0.67
Activated toolkits GD
Operating system Linux

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2009-01-02 23:33

the code in question:
http://fisheye3.atlassian.com/browse/gallery/trunk/gallery2/modules/core/classes/GalleryUtilities.class?r=17582#l387

googling for the error yields:
http://drupal.org/node/105316
http://bugs.php.net/bug.php?id=31303

doesn't help much. the question is why / where is GalleryUtilities::removeRequestVariable() called with a wrong $key.

quick fix:
change line 387 of modules/core/classes/GalleryUtilities.class from:
unset($array[$key]);
to:
if (is_array($array)) unset($array[$key]);

personally, i'd also add an else case to log the call stack which led to that invalid call.
at the top of the function, add $originalArrayPath = $keyPath;
and at the bottom of the function:
if (is_array($array)) {
unset($array[$key]);
} else {
$ret = GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__, 'Array path: ' . print_r($originalArrayPath, true));
GalleryCoreApi::addEventLogEntry('Gallery Error', 'Unable to remove request variable', $ret->getAsText());
}

then you can go to g2's site admin -> event log, to see if there are any entries for that issue from time to time.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
algurgazan

Joined: 2007-02-22
Posts: 5
Posted: Sun, 2009-01-04 19:49

thanks for the reply! i've made the changes you suggested, and i'm getting a really filled event log now.. this is the error:

Error (ERROR_LOG_LEVEL, ERROR_BAD_PARAMETER) : Array path: Array
(
    [0] => g2_GALLERYSID
)
 in modules/core/classes/GalleryUtilities.class at line 392 (GalleryCoreApi::error) 
in modules/core/classes/GalleryUtilities.class at line 364 (GalleryUtilities::_internalRemoveRequestVariable) 
in modules/core/classes/GallerySession.class at line 471 (GalleryUtilities::removeRequestVariable) 
in modules/core/classes/GallerySession.class at line 502 (GallerySession::reset) 
in modules/core/classes/helpers/GalleryUserHelper_medium.class at line 362 (GallerySession::regenerate) 
in modules/core/classes/helpers/GalleryEventHelper_simple.class at line 59 (GalleryUserHelper_medium::handleEvent) 
in modules/core/classes/GalleryCoreApi.class at line 2238 (GalleryEventHelper_simple::postEvent) 
in modules/core/classes/GalleryEmbed.class at line 310 (GalleryCoreApi::postEvent) 
in modules/core/classes/GalleryEmbed.class at line 270 (GalleryEmbed::login) 
in modules/core/classes/GalleryEmbed.class at line 120 (GalleryEmbed::checkActiveUser) 
in ///public_html/plugins/p39_gallery/g2embed.php at line 108 (GalleryEmbed::init) 
in ///public_html/skins/clearly/clearly_2.php at line 165
in ///public_html/index.php at line 917
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2009-01-05 08:16

weird, it says that $_POST is not an array.
does your integration (public_html/index.php, clearly/clearly_2.php, g2embed.php, ...) redefine $_POST? if so, it isn't doing it correctly.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage