@@ -165,6 +165,8 @@ class MutatingScope implements Scope
165165
166166 private bool $ treatPhpDocTypesAsCertain ;
167167
168+ private bool $ objectFromNewClass ;
169+
168170 private bool $ afterExtractCall ;
169171
170172 private ?Scope $ parentScope ;
@@ -195,6 +197,7 @@ class MutatingScope implements Scope
195197 * @param array<MethodReflection|FunctionReflection> $inFunctionCallsStack
196198 * @param string[] $dynamicConstantNames
197199 * @param bool $treatPhpDocTypesAsCertain
200+ * @param bool $objectFromNewClass
198201 * @param bool $afterExtractCall
199202 * @param Scope|null $parentScope
200203 */
@@ -224,6 +227,7 @@ public function __construct(
224227 array $ inFunctionCallsStack = [],
225228 array $ dynamicConstantNames = [],
226229 bool $ treatPhpDocTypesAsCertain = true ,
230+ bool $ objectFromNewClass = false ,
227231 bool $ afterExtractCall = false ,
228232 ?Scope $ parentScope = null
229233 )
@@ -257,6 +261,7 @@ public function __construct(
257261 $ this ->inFunctionCallsStack = $ inFunctionCallsStack ;
258262 $ this ->dynamicConstantNames = $ dynamicConstantNames ;
259263 $ this ->treatPhpDocTypesAsCertain = $ treatPhpDocTypesAsCertain ;
264+ $ this ->objectFromNewClass = $ objectFromNewClass ;
260265 $ this ->afterExtractCall = $ afterExtractCall ;
261266 $ this ->parentScope = $ parentScope ;
262267 }
@@ -2204,6 +2209,7 @@ public function doNotTreatPhpDocTypesAsCertain(): Scope
22042209 $ this ->inFunctionCallsStack ,
22052210 $ this ->dynamicConstantNames ,
22062211 false ,
2212+ $ this ->objectFromNewClass ,
22072213 $ this ->afterExtractCall ,
22082214 $ this ->parentScope
22092215 );
@@ -4641,6 +4647,10 @@ private function getTypeToInstantiateForNew(Type $type): Type
46414647 foreach ($ type ->getTypes () as $ innerType ) {
46424648 $ decidedType = $ decideType ($ innerType );
46434649 if ($ decidedType === null ) {
4650+ if ($ this ->objectFromNewClass ) {
4651+ return new ObjectWithoutClassType ();
4652+ }
4653+
46444654 return new MixedType (false , new StringType ());
46454655 }
46464656
@@ -4652,6 +4662,10 @@ private function getTypeToInstantiateForNew(Type $type): Type
46524662
46534663 $ decidedType = $ decideType ($ type );
46544664 if ($ decidedType === null ) {
4665+ if ($ this ->objectFromNewClass ) {
4666+ return new ObjectWithoutClassType ();
4667+ }
4668+
46554669 return new MixedType (false , new StringType ());
46564670 }
46574671
0 commit comments