Problem/Motivation
When running the node_link_report module on PHP 8.2+, the following deprecation is logged:
Deprecated function: Creation of dynamic property
Drupal\node_link_report\Service\LinkChecker::$additionalDomainsAsInternal is deprecated in
Drupal\node_link_report\Service\LinkChecker->getDomains()
on this line:
$this->$type = explode(',', $domain_list);
This happens inside LinkChecker::getDomains() when it is called from LinkChecker::isExternal().
Steps to reproduce
Inside getDomains():
$this->$type = explode(',', $domain_list);
With $type = 'additionalDomainsAsInternal', this becomes:
$this->additionalDomainsAsInternal = [...];
There is no declared property named $additionalDomainsAsInternal on LinkChecker, so PHP creates it dynamically. Dynamic properties are deprecated in PHP 8.2, which is exactly why the deprecation is triggered.
In other words: the class already has a typed property $additional_domains_as_internal, but the code is silently populating a different, undeclared property with a different name.
Proposed resolution
Update the call to getDomains() in isExternal() to use the correct snake_case key, so it aligns with both the declared property and the configuration key:
private function isExternal($url) {
// Now
// $internal_domains = $this->getDomains('additionalDomainsAsInternal');
// After the fix
$internal_domains = $this->getDomains('additional_domains_as_internal');
// Add the actual host.
$internal_domains[] = $this->requestStack->getCurrentrequest()->getHost();
$url_host = parse_url($url, PHP_URL_HOST);
return (in_array($url_host, $internal_domains)) ? FALSE : TRUE;
}
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | node_link_report_3559877-deprecation_err.patch | 614 bytes | vlyalko |
Issue fork node_link_report-3559877
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
vlyalko commentedComment #5
swirtvlyalko. Thank you for catching this and submitting a patch. I converted it to an MR so that testing pipeline and preview environments will be build.
Comment #7
swirtComment #9
swirtReleased as 8.x-1.24
Comment #10
vlyalko commentedThank you, @swirt!
Comment #11
liam morland