diff --git a/src/TypeSystem/CompositeTypeCheckerTrait.php b/src/TypeSystem/CompositeTypeCheckerTrait.php index 8ce63cdd..77762b4d 100644 --- a/src/TypeSystem/CompositeTypeCheckerTrait.php +++ b/src/TypeSystem/CompositeTypeCheckerTrait.php @@ -35,7 +35,11 @@ trait CompositeTypeCheckerTrait // TYPE_VAR means that the expression is dynamic or its result cannot // be represented by the current scalar type system. It must retain the // runtime type check. - if ($this->detectTypeOfExpr($value) === Type::VAR && !$this->isNullExpr($value)) { + // A reference (TYPE_REF) is a Variant reference whose concrete type is + // only known at runtime (e.g. an undefined variable auto-created by a + // by-reference argument), so it is treated the same way. + $valueType = $this->detectTypeOfExpr($value); + if (($valueType === Type::VAR || $valueType === Type::REF) && !$this->isNullExpr($value)) { return self::COMPOSITE_TYPE_UNKNOWN; } diff --git a/tests/compiler/static/static-call-byref-undefined-var.phpt b/tests/compiler/static/static-call-byref-undefined-var.phpt new file mode 100644 index 00000000..e51f81d5 --- /dev/null +++ b/tests/compiler/static/static-call-byref-undefined-var.phpt @@ -0,0 +1,38 @@ +--TEST-- +Static method call passing an undefined variable by reference (late static binding) +--FILE-- + +--EXPECT-- +string(4) "test" +string(4) "test"