Page MenuHomePhabricator

PHP Fatal error: Cannot use object of type stdClass as array in MobileFrontend.hooks.php on line 304
Closed, ResolvedPublic

Description

[2014-07-07 14:37:40] Fatal error: Cannot use object of type stdClass as array at /usr/local/apache/common-local/php-1.24wmf11/extensions/MobileFrontend/includes/MobileFrontend.hooks.php on line 304
Server: mw1060
Method: GET
URL: http://ta.wikipedia.org/w/index.php?title=%E0%AE%9A%E0%AE%BF%E0%AE%B1%E0%AE%AA%E0%AF%8D%E0%AE%AA%E0%AF%81:History/%E0%AE%B5%E0%AE%B0%E0%AE%B2%E0%AE%BE%E0%AE%B1%E0%AF%8D%E0%AE%B1%E0%AF%81_%E0%AE%AE%E0%AF%8A%E0%AE%B4%E0%AE%BF%E0%AE%AF%E0%AE%BF%E0%AE%AF%E0%AE%B2%E0%AF%8D&mobileaction=toggle_view_mobile
Backtrace:
#0 /usr/local/apache/common-local/php-1.24wmf11/extensions/MobileFrontend/includes/MobileFrontend.hooks.php(304): MobileFrontendHooks::onSpecialPage_initList()
#1 [internal function]: MobileFrontendHooks::onSpecialPage_initList(Object(stdClass))
#2 /usr/local/apache/common-local/php-1.24wmf11/includes/Hooks.php(206): call_user_func_array('MobileFrontendH...', Array)
#3 /usr/local/apache/common-local/php-1.24wmf11/includes/GlobalFunctions.php(4038): Hooks::run('SpecialPage_ini...', Array, NULL)
#4 /usr/local/apache/common-local/php-1.24wmf11/includes/specialpage/SpecialPageFactory.php(218): wfRunHooks('SpecialPage_ini...', Array)
#5 /usr/local/apache/common-local/php-1.24wmf11/includes/specialpage/SpecialPageFactory.php(243): SpecialPageFactory::getList()
#6 /usr/local/apache/common-local/php-1.24wmf11/includes/specialpage/SpecialPageFactory.php(280): SpecialPageFactory::getAliasList()
#7 /usr/local/apache/common-local/php-1.24wmf11/includes/Title.php(1047): SpecialPageFactory::resolveAlias('History/???????...')
#8 /usr/local/apache/common-local/php-1.24wmf11/includes/Wiki.php(191): Title->isSpecial('Badtitle')
#9 /usr/local/apache/common-local/php-1.24wmf11/includes/Wiki.php(603): MediaWiki->performRequest()
#10 /usr/local/apache/common-local/php-1.24wmf11/includes/Wiki.php(452): MediaWiki->main()
#11 /usr/local/apache/common-local/php-1.24wmf11/index.php(46): MediaWiki->run()
#12 /usr/local/apache/common-local/w/index.php(3): require('/usr/local/apac...')
#13 {main}


Version: 1.24rc
Severity: normal

Details

Reference
bz67596

Event Timeline

bzimport raised the priority of this task from to High.
bzimport set Reference to bz67596.
bzimport added a subscriber: Unknown Object (MLST).
Reedy created this task.Jul 7 2014, 2:47 PM

bingle-admin wrote:

Prioritization and scheduling of this bug is tracked on Trello card https://trello.com/c/wCCP87du

MaxSem added a comment.Jul 7 2014, 5:25 PM

That's caused by core's SpecialPageFactory::getList() providing wrong parameters to SpecialPage_initList hook: it sends an stdClass instead of array.

MaxSem added a comment.Sep 9 2014, 6:23 PM
  • Bug 70618 has been marked as a duplicate of this bug. ***

Yeah, it looks like the special page list is cast to an object, even though the function documentation says it returns an array. It looks like this was added back in 2011 to get around PHP's lack of anonymous function support. Now that we require PHP 5.3, which has anonymous function support, this object cast is no longer necessary.

I have no idea why this would have become a problem recently though.

Actually, I read the code comment backwards ( 'func()[$key]' not 'func[$key]()' ). It doesn't have anything to do with anonymous function support, but calling array values from function results immediately is also supported in PHP 5.3, so either way it isn't needed anymore.

So if we change the code in MobileFrontend from...

$list['Watchlist'] = 'SpecialMobileWatchlist';

...to...

$list->Watchlist = 'SpecialMobileWatchlist';

...it should fix the error, but the code has been like that forever, so I'm still mystified as to how this ever worked in the first place. Perhaps MaxSem will have more insight on this.

Actually, scratch that, I didn't notice the "if ( !is_object( self::$list ) ) {" outside the hook.

It looks like the hook is only ever called when the list is an array, before it is cast to an object, so I have no idea why it would be throwing that error.

Reedy added a comment.Sep 10 2014, 5:57 PM

So after some APC issues on a few servers causing problems for Wikidata, the number of these skyrocketed (again)...

Change 159526 had a related patch set uploaded by Reedy:
Don't cast SpecialPageFactory::$list to an object

https://gerrit.wikimedia.org/r/159526

Change 159526 merged by jenkins-bot:
Don't cast SpecialPageFactory::$list to an object

https://gerrit.wikimedia.org/r/159526

Change 159542 had a related patch set uploaded by Reedy:
Don't cast SpecialPageFactory::$list to an object

https://gerrit.wikimedia.org/r/159542

Change 159543 had a related patch set uploaded by Reedy:
Don't cast SpecialPageFactory::$list to an object

https://gerrit.wikimedia.org/r/159543

Change 159542 merged by MaxSem:
Don't cast SpecialPageFactory::$list to an object

https://gerrit.wikimedia.org/r/159542

Change 159543 merged by jenkins-bot:
Don't cast SpecialPageFactory::$list to an object

https://gerrit.wikimedia.org/r/159543

All patches mentioned in this report were merged - is there more work left to do here (if yes: please reset the bug report status to NEW or ASSIGNED), or can you close this ticket as RESOLVED FIXED?