1.2.596. Intersection Typehint

Intersection typehints allows the combination of several typehint for the same argument or return value.

Several typehints are specified at the same place as a single one. The different values are separated by a ampersand character &.

Intersection types are a PHP 8.1 new feature.

<?php

class Number {
    private A&B $object;
}
?>

See also PHP RFC: Pure intersection types, Type declarations and How the New Intersection Types in PHP 8.1 Give You More Flexibility.

1.2.596.1. Connex PHP features

1.2.596.1.1. Specs

Short name

Php/Php81IntersectionTypehint

Rulesets

All, Appinfo

Exakat since

2.3.3

PHP Version

With PHP 8.1 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud