Page MenuHomePhabricator

Premature access to service container
Open, HighPublic

Description

Seems mw phpunit tests result in some deprecated logspam after rMW47bb958f039c: Deprecate premature instantiation of services. from T153256: Unable to overwrite services using MediaWikiServices hook

03:02:02 PHP Deprecated:  Premature access to service container [Called from AbstractContent::getContentHandlerFactory in /workspace/src/includes/content/AbstractContent.php at line 103] in /workspace/src/includes/debug/MWDebug.php on line 376
03:02:02 PHP Deprecated:  Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /workspace/src/includes/MediaWikiServices.php at line 243] in /workspace/src/includes/debug/MWDebug.php on line 376
03:02:02 PHP Deprecated:  Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /workspace/src/includes/ServiceWiring.php at line 497] in /workspace/src/includes/debug/MWDebug.php on line 376
03:02:02 PHP Deprecated:  Premature access to service 'ContentHandlerFactory' [Called from AbstractContent::getContentHandlerFactory in /workspace/src/includes/content/AbstractContent.php at line 103] in /workspace/src/includes/debug/MWDebug.php on line 376
03:02:02 PHP Deprecated:  Premature access to service 'MainConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /workspace/src/includes/ServiceWiring.php at line 271] in /workspace/src/includes/debug/MWDebug.php on line 376
03:02:02 PHP Deprecated:  Premature access to service 'ConfigFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /workspace/src/includes/ServiceWiring.php at line 696] in /workspace/src/includes/debug/MWDebug.php on line 376
03:02:02 PHP Deprecated:  Premature access to service 'BootstrapConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /workspace/src/includes/ServiceWiring.php at line 249] in /workspace/src/includes/debug/MWDebug.php on line 376

Partial list of extensions to fix:

  • ArticleRatings
  • FundraisingEmailUnsubscribe
  • GoogleLogin

Event Timeline

DannyS712 updated the task description. (Show Details)

I'm confused - does this happen in production? Or does it make tests fail on the extension repos? If so, which tests?

I'm confused - does this happen in production? Or does it make tests fail on the extension repos? If so, which tests?

It cause logspam on various core patches in CI

https://gerrit.wikimedia.org/r/c/mediawiki/core/+/655134

https://integration.wikimedia.org/ci/job/wmf-quibble-core-vendor-mysql-php72-docker/45491/consoleFull

I munged some things so I could run phpunit on an instance in deployment-prep and got the following errors there (but not in a local install): P14230

GoogleLogin now errors with session_id(): Cannot change session id when headers already sent; is that distinct from this, or the same issue?

GoogleLogin now errors with session_id(): Cannot change session id when headers already sent; is that distinct from this, or the same issue?

It's much probably the same. That's one of the common errors that can happen in presence of PHP warnings/notices. In this case, triggering the deprecation warning causes PHP to output the deprecation text, together with some headers, thus making calls like session_id() fail. As a partial confirmation, the last error from https://integration.wikimedia.org/ci/job/quibble-vendor-mysql-php72-noselenium-docker/62789/console says:

Cannot modify header information - headers already sent by (output started at /workspace/src/includes/debug/MWDebug.php:376)

and in fact, MWDebug.php:376 is inside the sendRawDeprecated method.

Can you amend the messages to include a list of callers? In my developer environment the log is full of logpsam like below and it doesn't help figuring out what is causing it:

[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service container [Called from Hooks::run in /home/developer/mediawiki/workdir/includes/Hooks.php at line 135] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /home/developer/mediawiki/workdir/includes/MediaWikiServices.php at line 249] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/developer/mediawiki/workdir/includes/ServiceWiring.php at line 530] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'StatsdDataFactory' [Called from ObjectCache::newFromParams in /home/developer/mediawiki/workdir/includes/objectcache/ObjectCache.php at line 149] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'MainConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/developer/mediawiki/workdir/includes/ServiceWiring.php at line 1392] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'ConfigFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/developer/mediawiki/workdir/includes/ServiceWiring.php at line 729] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'BootstrapConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/developer/mediawiki/workdir/includes/ServiceWiring.php at line 272] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service container [Called from Hooks::run in /home/developer/mediawiki/workdir/includes/Hooks.php at line 135] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /home/developer/mediawiki/workdir/includes/MediaWikiServices.php at line 249] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/developer/mediawiki/workdir/includes/ServiceWiring.php at line 530] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'StatsdDataFactory' [Called from ObjectCache::newFromParams in /home/developer/mediawiki/workdir/includes/objectcache/ObjectCache.php at line 149] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'MainConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/developer/mediawiki/workdir/includes/ServiceWiring.php at line 1392] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'ConfigFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/developer/mediawiki/workdir/includes/ServiceWiring.php at line 729] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
[11-Mar-2021 10:24:11 UTC] PHP Deprecated:  Premature access to service 'BootstrapConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/developer/mediawiki/workdir/includes/ServiceWiring.php at line 272] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376

I did this locally and got:

Premature access to service container from require/require_once/ExtensionRegistry->loadFromQueue/ExtensionRegistry->exportExtractedData/SemanticMediaWiki::initExtension/SMW\Setup::initExtension/SMW\Setup::initConnectionProviders/SMW\MediaWiki\MwCollaboratorFactory->newConnectionProvider/SMW\Services\ServicesFactory->getSettings/Onoi\CallbackContainer\CallbackContainerBuilder->singleton/Onoi\CallbackContainer\CallbackContainerBuilder->getReturnValueFromSingletonFor/Onoi\CallbackContainer\CallbackContainerBuilder->getReturnValueFromCallbackHandlerFor/call_user_func_array/SMW\Services\SharedServicesContainer->SMW\Services\{closure}/SMW\Settings->loadFromGlobals/SMW\MediaWiki\HookDispatcher->onSettingsBeforeInitializationComplete/Hooks::run/MediaWiki\MediaWikiServices::getInstance [Called from Hooks::run in /home/developer/mediawiki/workdir/includes/Hooks.php at line 135] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
Premature access to service container from require/require_once/ExtensionRegistry->loadFromQueue/ExtensionRegistry->exportExtractedData/SemanticMediaWiki::initExtension/SMW\Setup::initExtension/SMW\Setup::initConnectionProviders/SMW\Elastic\ElasticFactory->newConnectionProvider/SMW\Services\ServicesFactory->getCache/Onoi\CallbackContainer\CallbackContainerBuilder->singleton/Onoi\CallbackContainer\CallbackContainerBuilder->getReturnValueFromSingletonFor/Onoi\CallbackContainer\CallbackContainerBuilder->getReturnValueFromCallbackHandlerFor/call_user_func_array/SMW\Services\SharedServicesContainer->SMW\Services\{closure}/SMW\CacheFactory->newMediaWikiCompositeCache/SMW\CacheFactory->newMediaWikiCache/ObjectCache::getInstance/ObjectCache::newFromId/ObjectCache::newFromParams/MediaWiki\MediaWikiServices::getInstance [Called from ObjectCache::newFromParams in /home/developer/mediawiki/workdir/includes/objectcache/ObjectCache.php at line 149] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376
Premature access to service container from SemanticMediaWiki::initExtension/SMW\Setup::initExtension/SMW\Setup::initConnectionProviders/SMW\Elastic\ElasticFactory->newConnectionProvider/SMW\Services\ServicesFactory->getCache/Onoi\CallbackContainer\CallbackContainerBuilder->singleton/Onoi\CallbackContainer\CallbackContainerBuilder->getReturnValueFromSingletonFor/Onoi\CallbackContainer\CallbackContainerBuilder->getReturnValueFromCallbackHandlerFor/call_user_func_array/SMW\Services\SharedServicesContainer->SMW\Services\{closure}/SMW\CacheFactory->newMediaWikiCompositeCache/SMW\CacheFactory->newMediaWikiCache/ObjectCache::getInstance/ObjectCache::newFromId/ObjectCache::newFromParams/ObjectCache::newAnything/ObjectCache::getInstance/ObjectCache::newFromId/ObjectCache::newFromParams/MediaWiki\MediaWikiServices::getInstance [Called from ObjectCache::newFromParams in /home/developer/mediawiki/workdir/includes/objectcache/ObjectCache.php at line 149] in /home/developer/mediawiki/workdir/includes/debug/MWDebug.php on line 376

So SMW needs to be added to the list of extensions to fix?

Can you amend the messages to include a list of callers? In my developer environment the log is full of logpsam like below and it doesn't help figuring out what is causing it:

I'd think that logging a stack trace is up to the logging code. Including the stack trace in the deprecation message itself is probably not a good idea. And including just the immediate caller is probably not very useful.

Have you tried running PHPUnit tests? In tests, the deprecation would throw and record a stack trace.

In any case, the first suspect in my mind would be code running from a MediaWikiServices hook handler.

I'm afraid running tests locally is a lost cause if you have anything "non-standard":

developer@dev:~/mediawiki/workdir/tests/phpunit (master)$ make safe
php phpunit.php --configuration /home/developer/mediawiki/workdir/tests/phpunit/suite.xml  --exclude-group Broken,Destructive,Stub
Using PHP 7.3.19-1~deb10u1
make: *** [Makefile:50: safe] Error 255

I fixed PHP Fatal error: Interface 'League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface' not found. After that I got this:

developer@dev:~/mediawiki/workdir/tests/phpunit (master)$ make safe
php phpunit.php --configuration /home/developer/mediawiki/workdir/tests/phpunit/suite.xml  --exclude-group Broken,Destructive,Stub
Using PHP 7.3.19-1~deb10u1
[82a44739b8ed756297be0bc2] [no req]   Error: Class 'SMW\Tests\JsonTestCaseScriptRunner' not found
Backtrace:
from /home/developer/mediawiki/workdir/extensions/SemanticMediaWiki/tests/phpunit/Benchmark/BenchmarkJsonScriptRunnerTest.php(18)
#0 /home/developer/mediawiki/workdir/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once()
#1 /home/developer/mediawiki/workdir/vendor/phpunit/phpunit/src/Util/FileLoader.php(54): PHPUnit\Util\FileLoader::load(string)
#2 /home/developer/mediawiki/workdir/vendor/phpunit/phpunit/src/Framework/TestSuite.php(384): PHPUnit\Util\FileLoader::checkAndLoad(string)
#3 /home/developer/mediawiki/workdir/vendor/phpunit/phpunit/src/Framework/TestSuite.php(482): PHPUnit\Framework\TestSuite->addTestFile(string)
#4 /home/developer/mediawiki/workdir/tests/phpunit/suites/ExtensionsTestSuite.php(31): PHPUnit\Framework\TestSuite->addTestFiles(array)
#5 /home/developer/mediawiki/workdir/tests/phpunit/suites/ExtensionsTestSuite.php(43): ExtensionsTestSuite->__construct()
#6 [internal function]: ExtensionsTestSuite::suite(string)
#7 /home/developer/mediawiki/workdir/vendor/phpunit/phpunit/src/Framework/TestSuite.php(463): ReflectionMethod->invoke(NULL, string)
#8 /home/developer/mediawiki/workdir/vendor/phpunit/phpunit/src/Util/Configuration.php(1061): PHPUnit\Framework\TestSuite->addTestFile(string)
#9 /home/developer/mediawiki/workdir/vendor/phpunit/phpunit/src/Util/Configuration.php(907): PHPUnit\Util\Configuration->getTestSuite(DOMElement, array)
#10 /home/developer/mediawiki/workdir/vendor/phpunit/phpunit/src/TextUI/Command.php(964): PHPUnit\Util\Configuration->getTestSuiteConfiguration(string)
#11 /home/developer/mediawiki/workdir/vendor/phpunit/phpunit/src/TextUI/Command.php(203): PHPUnit\TextUI\Command->handleArguments(array)
#12 /home/developer/mediawiki/workdir/tests/phpunit/phpunit.php(75): PHPUnit\TextUI\Command->run(array, boolean)
#13 /home/developer/mediawiki/workdir/maintenance/doMaintenance.php(112): PHPUnitMaintClass->execute()
#14 /home/developer/mediawiki/workdir/tests/phpunit/phpunit.php(134): require_once(string)
#15 {main}
make: *** [Makefile:50: safe] Error 255

I tried to fix that in the same way by adding the extensions' composer.json in composer.local.json, but got this:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - remove mediawiki/core dev-master|remove mediawiki/semantic-media-wiki dev-master
    - don't install mediawiki/semantic-media-wiki dev-master|remove mediawiki/core dev-master
    - Installation request for mediawiki/core dev-master -> satisfiable by mediawiki/core[dev-master].
    - Installation request for mediawiki/semantic-media-wiki dev-master#fb5a0a8775d69649b0edd667d1c7719a595b22b7 -> satisfiable by mediawiki/semantic-media-wiki[dev-master].

I gave up. To be fair, I expected to see a flood of failures, but not being able to run tests at all was a bit surprising.

If I had this problem with an extension, I'd just hack the code that triggers the warning to write a stack trace to a file, wait until I had captured a few, and then remove the hack again...

I see no good way to help with that from the core code side. As I said, whether a stack trace is logged or not is up to the logging backend. It can probably be configured somehow.

Just got this here. I know I'm not supposed to use $wgTitle, but I'm not sure what to do here. Pointers would be helpful.

Switch your test from MediaWikiUnitTestCase to MediaWikiIntegrationTestCase. MediaWikiUnitTestCase is specifically designed to prohibit access to global state, Title is all about global state, so you can't use Title in MediaWikiUniteTestCase.

I noticed these warnings this week when using a container to test an un-installed mw. The installation page had deprecation warnings (because of PHP.ini settings). It seems like this is not a good thing, but also a different bug.

Switch your test from MediaWikiUnitTestCase to MediaWikiIntegrationTestCase

... and move it out of the unit subdirectory.

Thanks, that worked!

Got the reported issue on:

  • MediaWiki 1.37.1 (2aa4a86) 18. Dez. 2021, 19:11
  • PHP 7.3.31-1~deb10u1 (apache2handler)
  • MariaDB 10.3.31-MariaDB-0+deb10u1

Same stack/error lines?

I'd say yes:

Deprecated: Premature access to service container [Called from ObjectCache::newFromParams in /../w/includes/objectcache/ObjectCache.php at line 149] in /../w/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /../w/includes/MediaWikiServices.php at line 267] in /../w/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /../w/includes/ServiceWiring.php at line 618] in /../w/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'StatsdDataFactory' [Called from ObjectCache::newFromParams in /../w/includes/objectcache/ObjectCache.php at line 149] in /../w/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'MainConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /../w/includes/ServiceWiring.php at line 1596] in /../w/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'ConfigFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /../w/includes/ServiceWiring.php at line 827] in /../w/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'BootstrapConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /../w/includes/ServiceWiring.php at line 346] in /../w/includes/debug/MWDebug.php on line 375

Edit: Pretty similar.

Same warnings logs here on each page load:
php7.4, Mediawiki 1.36.3, Nginx 1.14.2 (no docker)

2022/01/19 03:12:33 [error] 6075#6075: *418 FastCGI sent in stderr: "PHP message: PHP Deprecated:  Premature access to service container [Called from Hooks::run in /var/www/mediawiki/includes/Hooks.php at line 135] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /var/www/mediawiki/includes/MediaWikiServices.php at line 252] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 535] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  Premature access to service 'StatsdDataFactory' [Called from ObjectCache::newFromParams in /var/www/mediawiki/includes/objectcache/ObjectCache.php at line 149] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  Premature access to service 'MainConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 1424] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  Premature access to service 'ConfigFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 734] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  Premature access to service 'BootstrapConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 277] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  Premature access to service 'DBLoadBalancer' [Called from ObjectCache::{closure} in /var/www/mediawiki/includes/objectcache/ObjectCache.php at line 181] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376P

Readable:

Premature access to service container [Called from Hooks::run in /var/www/mediawiki/includes/Hooks.php at line 135] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  
Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /var/www/mediawiki/includes/MediaWikiServices.php at line 252] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  
Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 535] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  
Premature access to service 'StatsdDataFactory' [Called from ObjectCache::newFromParams in /var/www/mediawiki/includes/objectcache/ObjectCache.php at line 149] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  
Premature access to service 'MainConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 1424] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  
Premature access to service 'ConfigFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 734] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  
Premature access to service 'BootstrapConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 277] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PHP message: PHP Deprecated:  
Premature access to service 'DBLoadBalancer' [Called from ObjectCache::{closure} in /var/www/mediawiki/includes/objectcache/ObjectCache.php at line 181] in /var/www/mediawiki/includes/debug/MWDebug.php on line 376PH

If these occur in tests, it's typically because a data provider accesses the service container (often indirectly, e.g. by calling Title::newFromText instead of using Title::makeTitle). If this happens in production, it's very likely caused by an extension trying to do work before MW is fully initialized, most likely via the autoloader or in an extension callback.

To find the exact reason in this case, we need the full stack trace (see T273261#6908617). The immediate caller doesn't help us find the cause.

To find the exact reason in this case, we need the full stack trace (see T273261#6908617). The immediate caller doesn't help us find the cause.

In my case the full stack trace was just a line more than what was seen here. Anyhow this line hinted the Semantic Extra Special Properties extension which, after performing an upgrade of it, no longer causes the pain.

GoogleLogin in MediaWiki 1.37:

2022/03/28 17:12:34 [error] 2461732#2461732: *3448122 FastCGI sent in stderr: "PHP message: PHP Deprecated:  Premature access to service container [Called from GoogleLogin\GoogleLoginHooks::onSetup in /home/oer/w/extensions/GoogleLogin/includes/GoogleLoginHooks.php at line 174] in /home/oer/w/includes/debug/MWDebug.php on line 375

PHP message: PHP Deprecated:  Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /home/oer/w/includes/MediaWikiServices.php at line 267] in /home/oer/w/includes/debug/MWDebug.php on line 375

PHP message: PHP Deprecated:  Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/oer/w/includes/ServiceWiring.php at line 618] in /home/oer/w/includes/debug/MWDebug.php on line 375

PHP message: PHP Deprecated:  Premature access to service 'ConfigFactory' [Called from GoogleLogin\GoogleLoginHooks::onSetup in /home/oer/w/extensions/GoogleLogin/includes/GoogleLoginHooks.php at line 175] in /home/oer/w/includes/debug/MWDebug.php on line 375

PHP message: PHP Deprecated:  Premature access to service 'BootstrapConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /home/oer/w/includes/ServiceWiring.php at line 346] in /home/oer/w/includes/debug/MWDebug.php on line 375

PHP message: PHP Deprecated:  Use of InternalParseBeforeSanitize hook (used in VariablesHooks::onInternalParseBeforeSanitize) was deprecated in MediaWiki 1.35. [Called from MediaWiki\HookContainer\HookContainer::run in /home/oer/w/includes/HookContainer/HookContainer.php at line 137] in /home/oer/w/includes/debug/MWDebug.php on line 375

PHP message: PHP Deprecated:  Use of $wgUser was deprecated in MediaWiki 1.35. [Called from MediaWiki\HookContainer\HookContainer::callLegacyHook in /home/oer/w/includes/HookContainer/HookContainer.php at line 338] in /home/oer/w/includes/debug/MWDebug.php on line 375PHP message:

PHP Deprecated:  Use of User::isLoggedIn was deprecated in MediaWiki 1.36. [Called from StubObject::_call in /h

i get these on every page load, also while running maintenance scripts

MediaWiki 1.38.0-beta (e5b8fb9e8f50bdc2ee25012285da2c222a5986ac)
PHP 7.4.26 (fpm-fcgi)

i used xdebug trace files to find the extension that caused the errors. in my case it was the class EmbedVideoHooks. You can check out its code in their gitlab repo. please note that it's an old commit and not the master branch. EDIT: i just checked the master branch, it's still the same code. there's also a merge request with a proposed fix.

below are the deprecation warnings that went away after disabling the extension and an excerpt of the trace file that helped me find the cause. anyhow ... i don't understand what's going on there. maybe it's helpful for others.

Deprecated: Premature access to service container [Called from ConfigFactory::getDefaultInstance in /var/www/mediawiki/includes/config/ConfigFactory.php at line 54] in /var/www/mediawiki/includes/debug/MWDebug.php on line 377

Deprecated: Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /var/www/mediawiki/includes/MediaWikiServices.php at line 282] in /var/www/mediawiki/includes/debug/MWDebug.php on line 377

Deprecated: Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 687] in /var/www/mediawiki/includes/debug/MWDebug.php on line 377

Deprecated: Premature access to service 'ConfigFactory' [Called from ConfigFactory::getDefaultInstance in /var/www/mediawiki/includes/config/ConfigFactory.php at line 54] in /var/www/mediawiki/includes/debug/MWDebug.php on line 377

Deprecated: Premature access to service 'BootstrapConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/mediawiki/includes/ServiceWiring.php at line 392] in /var/www/mediawiki/includes/debug/MWDebug.php on line 377
0.5417    9585440                 -> MediaWiki\MediaWikiServices->getConfigFactory() /var/www/mediawiki/includes/config/ConfigFactory.php:54
  0.5417    9585440                   -> MediaWiki\MediaWikiServices->getService($name = 'ConfigFactory') /var/www/mediawiki/includes/MediaWikiServices.php:808
  0.5417    9585520                     -> wfDeprecatedMsg($msg = 'Premature access to service \'ConfigFactory\'', $version = '1.36', $component = FALSE, $callerOffset = 3) /var/www/mediawiki/includes/MediaWikiServices.php:291
  0.5417    9585520                       -> MWDebug::deprecatedMsg($msg = 'Premature access to service \'ConfigFactory\'', $version = '1.36', $component = FALSE, $callerOffset = 4) /var/www/mediawiki/includes/GlobalFunctions.php:1038
  0.5417    9585520                         -> MWDebug::getCallerDescription($callerOffset = 4) /var/www/mediawiki/includes/debug/MWDebug.php:312
  0.5417    9585520                           -> wfDebugBacktrace($limit = ???) /var/www/mediawiki/includes/debug/MWDebug.php:422
  0.5417    9585520                             -> debug_backtrace() /var/www/mediawiki/includes/GlobalFunctions.php:1313
  0.5418    9593736                             -> array_slice($arg = [0 => ['file' => '/var/www/mediawiki/includes/debug/MWDebug.php', 'line' => 422, 'function' => 'wfDebugBacktrace', 'args' => [...]], 1 => ['file' => '/var/www/mediawiki/includes/debug/MWDebug.php', 'line' => 312, 'function' => 'getCallerDescription', 'class' => 'MWDebug', 'type' => '::', 'args' => [...]], 2 => ['file' => '/var/www/mediawiki/includes/GlobalFunctions.php', 'line' => 1038, 'function' => 'deprecatedMsg', 'class' => 'MWDebug', 'type' => '::', 'args' => [...]], 3 => ['file' => '/var/www/mediawiki/includes/MediaWikiServices.php', 'line' => 291, 'function' => 'wfDeprecatedMsg', 'args' => [...]], 4 => ['file' => '/var/www/mediawiki/includes/MediaWikiServices.php', 'line' => 808, 'function' => 'getService', 'class' => 'MediaWiki\\MediaWikiServices', 'object' => class MediaWiki\MediaWikiServices { ... }, 'type' => '->', 'args' => [...]], 5 => ['file' => '/var/www/mediawiki/includes/config/ConfigFactory.php', 'line' => 54, 'function' => 'getConfigFactory', 'class' => 'MediaWiki\\MediaWikiServices', 'object' => class MediaWiki\MediaWikiServices { ... }, 'type' => '->', 'args' => [...]], 6 => ['file' => '/var/www/mediawiki/extensions/EmbedVideo/EmbedVideo.hooks.php', 'line' => 75, 'function' => 'getDefaultInstance', 'class' => 'ConfigFactory', 'type' => '::', 'args' => [...]], 7 => ['file' => '/var/www/mediawiki/includes/registration/ExtensionRegistry.php', 'line' => 574, 'function' => 'onExtension', 'class' => 'EmbedVideoHooks', 'type' => '::', 'args' => [...]], 8 => ['file' => '/var/www/mediawiki/includes/registration/ExtensionRegistry.php', 'line' => 258, 'function' => 'exportExtractedData', 'class' => 'ExtensionRegistry', 'object' => class ExtensionRegistry { ... }, 'type' => '->', 'args' => [...]], 9 => ['file' => '/var/www/mediawiki/includes/Setup.php', 'line' => 265, 'function' => 'loadFromQueue', 'class' => 'ExtensionRegistry', 'object' => class ExtensionRegistry { ... }, 'type' => '->', 'args' => [...]], 10 => ['file' => '/var/www/mediawiki/includes/WebStart.php', 'line' => 93, 'args' => [...], 'function' => 'require_once'], 11 => ['file' => '/var/www/mediawiki/index.php', 'line' => 44, 'args' => [...], 'function' => 'require']], $offset = 1) /var/www/mediawiki/includes/GlobalFunctions.php:1313
  0.5418    9586056                         -> MWDebug::formatCallerDescription($msg = 'Premature access to service \'ConfigFactory\'', $caller = ['file' => '/var/www/mediawiki/includes/config/ConfigFactory.php at line 54', 'func' => 'ConfigFactory::getDefaultInstance']) /var/www/mediawiki/includes/debug/MWDebug.php:314

i used xdebug trace files to find the extension that caused the errors. in my case it was the class EmbedVideoHooks. You can check out its code in their gitlab repo. please note that it's an old commit and not the master branch. EDIT: i just checked the master branch, it's still the same code. there's also a merge request with a proposed fix.

EmbedVideoHooks has this in ints extension.json: "callback": "EmbedVideoHooks::onExtension". This callback is executed when extensions get registered, before MediaWikiServices is (properly) initialized. Since EmbedVideoHooks::onExtension calls MediaWikiServices::getInstance(), you get that warning.

More broadly, the issue is that we currently do not have a good place for extensions to initialize dynamic defaults. The registration callback *should* be that place, but it currently is not. One way to fix EmbedVideoHooks for now is to change the registration of the initialization hook to "ExtensionFunctions": [ "EmbedVideoHooks::onExtension" ]. That should work for now, but it is bound to break again later. Another solution would be to not use MediaWikiConfig:.getInstance()->getMainConfig() in EmbedVideoHooks::onExtensio, but instead do $config = new GlobalVarConfig( 'wg' ). That's not great, but an OK solution for now until the situation has been sorted out.

I filed T305917 for tracking this. The more general context is T297166.

I also encounter the exact same error but I do not have EmbedVideoHooks Extension installed. I also try to disable all extension and run updatePublicSuffixArray.php put the error still exist both on every page of the wiki and running the updatePublicSuffixArray.php script.

Deprecated: Premature access to service container [Called from GoogleLogin\GoogleLoginHooks::onSetup in /var/www/html/extensions/GoogleLogin/includes/GoogleLoginHooks.php at line 174] in /var/www/html/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /var/www/html/includes/MediaWikiServices.php at line 267] in /var/www/html/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/html/includes/ServiceWiring.php at line 618] in /var/www/html/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'ConfigFactory' [Called from GoogleLogin\GoogleLoginHooks::onSetup in /var/www/html/extensions/GoogleLogin/includes/GoogleLoginHooks.php at line 175] in /var/www/html/includes/debug/MWDebug.php on line 375

Deprecated: Premature access to service 'BootstrapConfig' [Called from Wikimedia\Services\ServiceContainer::{closure} in /var/www/html/includes/ServiceWiring.php at line 346] in /var/www/html/includes/debug/MWDebug.php on line 375

Change 835184 had a related patch set uploaded (by Owenjones; author: Owenjones):

[mediawiki/extensions/GoogleLogin@master] Fix premature access warnings

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

Change 937993 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/core@master] phpunit: Throw exception when MediaWikiServices is accessed too early

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

Change 937993 merged by jenkins-bot:

[mediawiki/core@master] phpunit: Throw exception when MediaWikiServices is accessed too early

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

For the google login one, this was actively causing redirects to go to the wrong place, because it was initializing UrlUtilities when $wgCanonicalServer was "", before setup.php set it to the default value.

Change #835184 abandoned by Owenjones:

[mediawiki/extensions/GoogleLogin@master] Fix premature access warnings

Reason:

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