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

Command icon 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

vlyalko created an issue. See original summary.

vlyalko’s picture

swirt made their first commit to this issue’s fork.

swirt’s picture

vlyalko. 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.

  • swirt committed e08459ed on 8.x-1.x
    #3559877 Fix incorrect camel case
    
swirt’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

swirt’s picture

Status: Fixed » Closed (fixed)

Released as 8.x-1.24

vlyalko’s picture

Thank you, @swirt!

liam morland’s picture

Issue tags: -PHP 8.* deprecation +PHP 8.0