Page MenuHomePhabricator

Using null as an array offset is deprecated, use an empty string instead in SiteList
Closed, ResolvedPublic

Description

https://integration.wikimedia.org/ci/job/quibble-for-mediawiki-core-vendor-mysql-php85/3/consoleFull

13:59:58 227) InterwikiLookupAdapterTest::testIsValidInterwiki
13:59:58 Using null as an array offset is deprecated, use an empty string instead
13:59:58 
13:59:58 /workspace/src/includes/Site/SiteList.php:153
13:59:58 /workspace/src/includes/Site/SiteList.php:92
13:59:58 /workspace/src/includes/Site/SiteList.php:71
13:59:58 /workspace/src/tests/phpunit/unit/includes/Interwiki/InterwikiLookupAdapterTest.php:128
13:59:58 /workspace/src/tests/phpunit/unit/includes/Interwiki/InterwikiLookupAdapterTest.php:24
13:59:58 
13:59:58 228) InterwikiLookupAdapterTest::testFetch
13:59:58 Using null as an array offset is deprecated, use an empty string instead
13:59:58 
13:59:58 /workspace/src/includes/Site/SiteList.php:153
13:59:58 /workspace/src/includes/Site/SiteList.php:92
13:59:58 /workspace/src/includes/Site/SiteList.php:71
13:59:58 /workspace/src/tests/phpunit/unit/includes/Interwiki/InterwikiLookupAdapterTest.php:128
13:59:58 /workspace/src/tests/phpunit/unit/includes/Interwiki/InterwikiLookupAdapterTest.php:24
13:59:58 
13:59:58 229) InterwikiLookupAdapterTest::testGetAllPrefixes
13:59:58 Using null as an array offset is deprecated, use an empty string instead
13:59:58 
13:59:58 /workspace/src/includes/Site/SiteList.php:153
13:59:58 /workspace/src/includes/Site/SiteList.php:92
13:59:58 /workspace/src/includes/Site/SiteList.php:71
13:59:58 /workspace/src/tests/phpunit/unit/includes/Interwiki/InterwikiLookupAdapterTest.php:128
13:59:58 /workspace/src/tests/phpunit/unit/includes/Interwiki/InterwikiLookupAdapterTest.php:24
13:59:58 
13:59:58 230) InterwikiLookupAdapterTest::testValidCovers
13:59:58 Using null as an array offset is deprecated, use an empty string instead
13:59:58 
13:59:58 /workspace/src/includes/Site/SiteList.php:153
13:59:58 /workspace/src/includes/Site/SiteList.php:92
13:59:58 /workspace/src/includes/Site/SiteList.php:71
13:59:58 /workspace/src/tests/phpunit/unit/includes/Interwiki/InterwikiLookupAdapterTest.php:128
13:59:58 /workspace/src/tests/phpunit/unit/includes/Interwiki/InterwikiLookupAdapterTest.php:24

Event Timeline

		$this->byGlobalId[$site->getGlobalId()] = $index;
		$this->byInternalId[$site->getInternalId()] = $index;

Both those site functions can return null, so while the error is showing for the second, it could presumably happen for the first.

Noting that this causes a *lot* of console-spam when running (e.g.) composer phpunit:entrypoint locally on PHP 8.5...
...by which I mean, 138 lines of this before the tests started running:

PHP Deprecated:  Using null as an array offset is deprecated, use an empty string instead in /[...]/includes/Site/SiteList.php on line 153

...and 138 lines of this after the tests had completed:

Deprecated: Using null as an array offset is deprecated, use an empty string instead in /[...]/includes/Site/SiteList.php on line 153
 

A simple fix to keep the "same" behaviour would be to have:

		$this->byGlobalId[$site->getGlobalId() ?? ''] = $index;
		$this->byInternalId[$site->getInternalId() ?? ''] = $index;

But whether this is actually potentially losing data in reality? Or only in synthetic tests?

The InterwikiLookupAdapterTest file doesn't seem to call setInternalId anywhere...

For the test, we could set it to a value of 1 or similar.

But that only fixes the test. Based on what you've said above, this is causing logspam on various other code executions/tests...

Noting that this causes a *lot* of console-spam when running (e.g.) composer phpunit:entrypoint locally on PHP 8.5 [...]

(fwiw, using xdebug, I found out that these specific deprecation warnings seem to be coming from the SiteListTest data provider:)

Deprecated:  Using null as an array offset is deprecated, use an empty string instead in /[...]/mediawiki/includes/Site/SiteList.php on line 153
Stack trace:
[...]
  17. /[...]/mediawiki/vendor/phpunit/phpunit/src/Util/Annotation/DocBlock.php:421
  18. /[...]/mediawiki/tests/phpunit/includes/Site/SiteListTest.php:30
  19. /[...]/mediawiki/includes/Site/SiteList.php:71
  20. /[...]/mediawiki/includes/Site/SiteList.php:92

		$this->byInternalId[$site->getInternalId() ?? ''] = $index;

T90167: Drop "internal id" field, use global ID instead. seems potentially related to that specifically. (But, as you mention, getGlobalId() can also return null)

Change #1227873 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@master] tests: Set internal site id in InterwikiLookupAdapterTest

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

Change #1227873 merged by jenkins-bot:

[mediawiki/core@master] Site: Handle non-stored Site objects in SiteList

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

Change #1227962 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@REL1_45] Site: Handle non-stored Site objects in SiteList

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

Change #1227968 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@REL1_44] Site: Handle non-stored Site objects in SiteList

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

Change #1227969 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@REL1_43] Site: Handle non-stored Site objects in SiteList

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

Change #1227962 merged by jenkins-bot:

[mediawiki/core@REL1_45] Site: Handle non-stored Site objects in SiteList

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

Change #1227969 merged by jenkins-bot:

[mediawiki/core@REL1_43] Site: Handle non-stored Site objects in SiteList

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

Change #1227968 merged by jenkins-bot:

[mediawiki/core@REL1_44] Site: Handle non-stored Site objects in SiteList

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