<?php
declare(strict_types=1);
interface I1 {}
interface I2 {}
class Both implements I1, I2 {}
function accepts((I1&I2) $o): string { return 'ok'; }
function returns(): (I1&I2) { return new Both(); }
var_export(accepts(new Both()));
var_export(returns() instanceof Both);
Category
language· php-src-strict · regression vs closed #3094Problem
PHP 8.2 DNF allows parenthesized intersection-only types such as
(I1&I2) $paramandfunction f(): (I1&I2). UnparenthesizedI1&I2 $paramand union forms like(I1&I2)|nullcompile here, but parenthesized intersection-only positions fail at parse withunexpected T_VARIABLE, expecting '|'.php-src reference
Zend/zend_compile.c—zend_compile_arg_type, DNF type parsingRepro (failure today)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/issue-dnf-paren-intersection-param.php' php test/repro/issue-dnf-paren-intersection-param.phpI1&I2 $o(I1&I2) $ofunction f(): (I1&I2)Scope (PHP-in-PHP)
PHPCfgtype reconstruction — accept parenthesized intersection leaf in DNF positionslib/VM.php+lib/JIT/runtime checks once parse succeeds (reuse existing intersection helpers from Language: DNF types — union of intersections (PHP 8.2) #3094)test/repro/issue-dnf-paren-intersection-param.phpDone when
(I1&I2)without parse errornew Both()and rejects non-implementors./script/ci-fast.sh --filter dnf_paren_intersectionif addedRelated