Complete the code to declare a function that accepts a parameter which must implement both interfaces A and B.
<?php
interface A {}
interface B {}
function test([1] $param) {
// function body
}
?>In PHP, intersection types are declared using the & symbol between interface names.
Complete the code to declare a variable with an intersection type of interfaces X and Y.
<?php
interface X {}
interface Y {}
/** @var [1] */
$obj;
?>Intersection types use & to specify that the variable must implement both interfaces.
Fix the error in the function parameter type declaration to correctly use intersection types.
<?php
interface M {}
interface N {}
function example([1] $param) {
// code
}
?>The correct syntax for intersection types uses & between interface names.
Fill both blanks to declare a function that accepts a parameter implementing interfaces P and Q, and returns a value of the same intersection type.
<?php
interface P {}
interface Q {}
function process([1] $input): [2] {
return $input;
}
?>Both the parameter and return type must use the intersection type with &.
Fill all three blanks to declare a class implementing interfaces U and V, and a function that accepts a parameter with the same intersection type.
<?php
interface U {}
interface V {}
class MyClass implements [1] {
public function handle([2] $param): void {
// handle param
}
}
function callHandle([3] $obj) {
$obj->handle($obj);
}
?>The class implements interfaces U and V using 'U,V', and the parameter types use the intersection type 'U&V'.