(Translated by https://www.hiragana.jp/)
⚓ T364967 PHP Warning: array_key_exists(): The first argument should be either a string or an integer
Page MenuHomePhabricator

PHP Warning: array_key_exists(): The first argument should be either a string or an integer
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
labels.normalized_message
[{reqId}] {exception_url}   PHP Warning: array_key_exists(): The first argument should be either a string or an integer
error.stack_trace
from /srv/mediawiki/php-1.43.0-wmf.5/includes/site/SiteList.php(223)
#0 [internal function]: MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.43.0-wmf.5/includes/site/SiteList.php(223): array_key_exists(boolean, array)
#2 /srv/mediawiki/php-1.43.0-wmf.5/includes/site/CachingSiteStore.php(109): MediaWiki\Site\SiteList->hasSite(boolean)
#3 /srv/mediawiki/php-1.43.0-wmf.5/includes/WikiMap/WikiMap.php(91): MediaWiki\Site\CachingSiteStore->getSite(boolean)
#4 /srv/mediawiki/php-1.43.0-wmf.5/includes/WikiMap/WikiMap.php(46): MediaWiki\WikiMap\WikiMap::getWikiWikiReferenceFromSites(boolean)
#5 /srv/mediawiki/php-1.43.0-wmf.5/includes/WikiMap/WikiMap.php(174): MediaWiki\WikiMap\WikiMap::getWiki(boolean)
#6 /srv/mediawiki/php-1.43.0-wmf.5/extensions/CampaignEvents/src/FrontendModules/EventDetailsModule.php(235): MediaWiki\WikiMap\WikiMap::getForeignURL(boolean, string)
#7 /srv/mediawiki/php-1.43.0-wmf.5/extensions/CampaignEvents/src/FrontendModules/EventDetailsModule.php(122): MediaWiki\Extension\CampaignEvents\FrontendModules\EventDetailsModule->getInfoColumn(MediaWiki\User\User, MediaWiki\Output\OutputPage, boolean, boolean, boolean, boolean, integer)
#8 /srv/mediawiki/php-1.43.0-wmf.5/extensions/CampaignEvents/src/Special/SpecialEventDetails.php(205): MediaWiki\Extension\CampaignEvents\FrontendModules\EventDetailsModule->createContent(MediaWiki\User\User, boolean, boolean, boolean, MediaWiki\Output\OutputPage)
#9 /srv/mediawiki/php-1.43.0-wmf.5/includes/specialpage/SpecialPage.php(719): MediaWiki\Extension\CampaignEvents\Special\SpecialEventDetails->execute(string)
#10 /srv/mediawiki/php-1.43.0-wmf.5/includes/specialpage/SpecialPageFactory.php(1680): MediaWiki\SpecialPage\SpecialPage->run(string)
#11 /srv/mediawiki/php-1.43.0-wmf.5/includes/actions/ActionEntryPoint.php(502): MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, MediaWiki\Context\RequestContext)
#12 /srv/mediawiki/php-1.43.0-wmf.5/includes/actions/ActionEntryPoint.php(145): MediaWiki\Actions\ActionEntryPoint->performRequest()
#13 /srv/mediawiki/php-1.43.0-wmf.5/includes/MediaWikiEntryPoint.php(199): MediaWiki\Actions\ActionEntryPoint->execute()
#14 /srv/mediawiki/php-1.43.0-wmf.5/index.php(58): MediaWiki\MediaWikiEntryPoint->run()
#15 /srv/mediawiki/w/index.php(3): require(string)
#16 {main}
Impact
Notes

This is a new error in 1.43.0-wmf.5 (no occurrences in 1.43.0-wmf.4). Number is small so far.

Details

Request URL
https://meta.wikimedia.org/w/index.php?tab=*&title=*

Event Timeline

Change #1031847 had a related patch set uploaded (by Wargo; author: Wargo):

[mediawiki/extensions/CampaignEvents@master] Don't get foreign wiki data if event is on local wiki

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

Hm. I would like to add real type hints to WikiMap and related class, because there are a lot of methods that are documented to only accept string, but don't have a type hint, and therefore their failure states may not be obvious. This is an example of that. Interestingly though, this warning is only emitted in PHP 7.4: starting with PHP 8, array_key_exists accepts more types than just string for its first parameter. I looked at a bunch of methods that could end up being called when WikiMap::getWiki is called across WikiMap, *SiteStore, and SiteConfiguration classes. They all seem to have one thing in common: the $wiki parameter is documented as a string, and the code only expects it to be a string. But yet, everything that those methods do with the wikiID parameter (array_key_exists, str_replace, string concatenation, array offset access, etc.) seems to work just fine with a boolean, as PHP just does some type juggling and doesn't emit any notices. There's nothing I could find that would throw an error or even emit a notice (at least in PHP 8.1), and the implicit cast from false to '' probably doesn't alter the correctness of the code. All in all, this means I didn't find any strong enough reason to add type hints, and that I'll stick with the CampaignEvents fix for now.

brennen subscribed.

Still seeing these in 1.43.0-wmf.9 (T361403).

This continues to happen steadily, and is often the most visible error in logspam-watch. Seems to all be CampaignEvents related.

2024-06-20-09:17:24.png (249×633 px, 14 KB)

2024-06-20-09:16:34.png (196×1 px, 58 KB)

Hi @Wargo, are you still planning to work on this? Please let me know if you need any help.

Daimona added a subscriber: Wargo.

Happen on CI as well, providing a flaky test.

That's weird and I'm not sure why it'd do that, but at any rate, I will finish working on the patch.

....but at any rate, I will finish working on the patch.

Thanks!

Change #1031847 merged by jenkins-bot:

[mediawiki/extensions/CampaignEvents@master] Don't get foreign wiki data if event is on local wiki

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

Change #1031847 merged by jenkins-bot:

[mediawiki/extensions/CampaignEvents@master] Don't get foreign wiki data if event is on local wiki

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

This is rolling out on the 1.43.0-wmf.15 train.

vaughnwalters subscribed.

Marking this as done as logstash is no longer showing the error when visiting this event