diff --git a/src/Type/Php/SimpleXMLElementXpathMethodReturnTypeExtension.php b/src/Type/Php/SimpleXMLElementXpathMethodReturnTypeExtension.php
index 84dc243c24..45715f21be 100644
--- a/src/Type/Php/SimpleXMLElementXpathMethodReturnTypeExtension.php
+++ b/src/Type/Php/SimpleXMLElementXpathMethodReturnTypeExtension.php
@@ -6,9 +6,9 @@
use PHPStan\Analyser\Scope;
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\Reflection\MethodReflection;
-use PHPStan\Type\ArrayType;
+use PHPStan\Reflection\ParametersAcceptorSelector;
+use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
-use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
@@ -31,11 +31,12 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type
{
- if (!isset($methodCall->getArgs()[0])) {
+ $args = $methodCall->getArgs();
+ if (!isset($args[0])) {
return null;
}
- $argType = $scope->getType($methodCall->getArgs()[0]->value);
+ $argType = $scope->getType($args[0]->value);
$xmlElement = new SimpleXMLElement('');
@@ -53,7 +54,9 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
return null;
}
- return new ArrayType(new MixedType(), $scope->getType($methodCall->var));
+ $variant = ParametersAcceptorSelector::selectFromArgs($scope, $args, $methodReflection->getVariants());
+
+ return TypeCombinator::remove($variant->getReturnType(), new ConstantBooleanType(false));
}
}
diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
index c939f95628..8e60be9b4f 100644
--- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
+++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
@@ -3144,7 +3144,7 @@ public static function dataBinaryOperations(): array
'$simpleXMLWritingXML',
],
[
- 'array',
+ 'array|null',
'$simpleXMLRightXpath',
],
[
diff --git a/tests/PHPStan/Analyser/nsrt/bug-9714.php b/tests/PHPStan/Analyser/nsrt/bug-9714.php
index 3dbb7d1b87..5629966029 100644
--- a/tests/PHPStan/Analyser/nsrt/bug-9714.php
+++ b/tests/PHPStan/Analyser/nsrt/bug-9714.php
@@ -10,7 +10,6 @@ public function exampleFunction(): void
{
$xml = new \SimpleXmlElement('');
$elements = $xml->xpath('//data');
- assertType('array', $elements);
+ assertType('array|null', $elements);
}
}
-