Problem/Motivation
After upgrading to PHP 8.2 (which is necessary this year with PHP 8.1 approaching end-of-life), I get this deprecation notice:
Deprecated function: Creation of dynamic property Drupal\content_lock\ContentLock\ContentLock::$time is deprecated in Drupal\content_lock\ContentLock\ContentLock->__construct() (line 139 of modules/contrib/content_lock/src/ContentLock/ContentLock.php).
Drupal\content_lock\ContentLock\ContentLock->__construct(Object, Object, Object, Object, Object, Object, Object, Object, Object) (Line: 259)
Drupal\Component\DependencyInjection\Container->createService(Array, 'content_lock') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('content_lock') (Line: 197)
Drupal::service('content_lock') (Line: 236)
content_lock_views_data() (Line: 228)
Drupal\views\ViewsData->Drupal\views\{closure}(Object, 'content_lock') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('views_data', Object) (Line: 227)
Drupal\views\ViewsData->getData() (Line: 151)
Drupal\views\ViewsData->get('block_content') (Line: 93)
Drupal\ds\Plugin\Derivative\DsEntityRow->getDerivativeDefinitions(Array) (Line: 101)
Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives(Array) (Line: 87)
Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions() (Line: 323)
Drupal\Core\Plugin\DefaultPluginManager->findDefinitions() (Line: 205)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 22)
Drupal\Core\Plugin\DefaultPluginManager->getDefinition('data_entity') (Line: 16)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('data_entity', Array) (Line: 83)
Drupal\Component\Plugin\PluginManagerBase->createInstance('data_entity') (Line: 821)
Drupal\views\Plugin\views\display\DisplayPluginBase->getPlugin('row') (Line: 129)
Drupal\views\Plugin\views\style\StylePluginBase->init(Object, Object, Array) (Line: 824)
Drupal\views\Plugin\views\display\DisplayPluginBase->getPlugin('style') (Line: 346)
Drupal\rest\Plugin\views\display\RestExport->collectRoutes(Object) (Line: 120)
Drupal\views\EventSubscriber\RouteSubscriber->routes()
call_user_func(Array) (Line: 146)
Drupal\Core\Routing\RouteBuilder->rebuild() (Line: 83)
Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild() (Line: 384)
Drupal\Core\Extension\ModuleInstaller->install(Array, 1) (Line: 83)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array) (Line: 502)
Drupal\system\Form\ModulesListForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 129)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('system_modules', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
Install content_lock on a Drupal site with PHP 8.2. As far as I can tell, that's all that is needed to reproduce.
Proposed resolution
I found this: https://stackoverflow.com/questions/74878889/php-warning-deprecated-crea...
From that, I tried adding this explicit definition of $time between the other defined class variables and the constructor.
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface $time
*
*/
protected $time;
If I've followed what changed with PHP correctly, that seems like all that is necessary, but I just started looking into this so it's possible I'm missing something.