@@ -2540,12 +2540,30 @@ class ArgumentsHandler
25402540 }
25412541
25422542 // what the call writes back is described by PHPDoc (@param, @param-out,
2543- // a parameter-out extension) - natively only the parameter's own
2544- // type declaration is guaranteed
2543+ // a parameter-out extension) - natively only the parameter's own type
2544+ // can describe it: its declaration, or for a builtin its signature map
2545+ // entry. PHP checks a declaration only on the way in and a signature
2546+ // map entry not at all, so it holds only when the written-back type
2547+ // fits inside it. preg_match() with PREG_OFFSET_CAPTURE writes arrays
2548+ // into a slot the signature map declares as string[].
25452549 bool currentIsExtended = false ;
25462550 if (UNEXPECTED (!isA (currentParameter, PT_CLASS_EXTENDED_PARAMETER_REFLECTION , currentIsExtended))) return false ;
25472551 zv::Val byRefNativeType = currentIsExtended ? parameterGetNativeType (currentParameter) : zv::Val::copyOf (byRefType.ref ());
25482552 if (UNEXPECTED (byRefNativeType.isUndef ())) return false ;
2553+ if (currentIsExtended) {
2554+ if (UNEXPECTED (Z_TYPE_P (byRefNativeType.raw ()) != IS_OBJECT )) {
2555+ zend_throw_error (NULL , " Call to a member function isSuperTypeOf() on %s" , zend_zval_value_name (byRefNativeType.raw ()));
2556+ return false ;
2557+ }
2558+ zv::Val fits = pt_type_op (Z_OBJ_P (byRefNativeType.raw ()), PT_OP_IS_SUPER_TYPE_OF , 1 , byRefType.raw ());
2559+ if (UNEXPECTED (fits.isUndef ())) return false ;
2560+ zend_long fitsValue = pt_type_result_trinary (fits.raw ());
2561+ if (UNEXPECTED (fitsValue < 0 )) return false ;
2562+ if (fitsValue != PT_TRI_YES ) {
2563+ byRefNativeType = pt_type_new_mixed_type ();
2564+ if (UNEXPECTED (byRefNativeType.isUndef ())) return false ;
2565+ }
2566+ }
25492567
25502568 zv::Val typeExpr = newNativeTypeExpr (byRefType.raw (), byRefNativeType.raw ());
25512569 if (UNEXPECTED (typeExpr.isUndef ())) return false ;
0 commit comments