PHPStan

These are contributions that we need to make to improve PHP8 compatibility detection.

Example configuration

parameters:
	phpVersion: 80000
	level: 5
	reportUnmatchedIgnoredErrors: false
	ignoreErrors:
		-	'#\\Drupal calls should be avoided in classes, use dependency injection instead#'
		-	'#Call to function [a-zA-Z0-9\\\\_\\(\\)]+ on a separate line has no effect.#'
		-	'#Expression \\"\\$[a-zA-Z0-9\\\\_\\[\\]\\"]+\\" on a separate line does not do anything.#'

Compatibility rules needed

match is now a reserved keyword.

function match() {
  // reserved in PHP 8
}

function match() definition causes a syntax error when phpVersion: 80000

------ ------------------------------------------------------------------------
  Line   upgrade_status_test_contrib_error.module
 ------ ------------------------------------------------------------------------
  19     Syntax error, unexpected T_MATCH, expecting T_STRING or '(' on line 19
 ------ ------------------------------------------------------------------------

Methods with the same name as the class are no longer interpreted as constructors. The __construct() method should be used instead.

<?php declare(strict_types=1);

final class Foo {

  private string $bar;

  public function Foo(string $bar) {
    $this->bar = $bar;
  }

  public function getBar(): string {
    return $this->bar;
  }

}

No error returned for Foo and no __construct

The ability to call non-static methods statically has been removed. Thus is_callable() will fail when checking for a non-static method with a classname (must check with an object instance).

function ability_to_call_non_static_methods() {
  // Should error
  $result1 = is_callable([FormBuilder::class, 'buildForm']);
  // Should not
  $result2 = is_callable([FormBuilder::class, 'trustedCallbacks']);
}