Skip to content

Commit

Permalink
Merge pull request #10134 from weirdan/fix-10132
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan authored Aug 20, 2023
2 parents 0922fa1 + 1474340 commit e085b73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1737,8 +1737,10 @@ private static function handleArrayAccessOnNamedObject(
?Union &$array_access_type,
bool &$has_array_access
): void {
$codebase = $statements_analyzer->getCodebase();
if (strtolower($type->value) === 'simplexmlelement'
|| $statements_analyzer->getCodebase()->classExtendsOrImplements($type->value, 'SimpleXMLElement')
|| ($codebase->classExists($type->value)
&& $codebase->classExtendsOrImplements($type->value, 'SimpleXMLElement'))
) {
$call_array_access_type = new Union([new TNull(), new TNamedObject('SimpleXMLElement')]);
} elseif (strtolower($type->value) === 'domnodelist' && $stmt->dim) {
Expand Down
21 changes: 21 additions & 0 deletions tests/ArrayAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,27 @@ function f($p): int {
',
'assertions' => ['$a===' => "array{1: 'b'}"],
],
'noCrashOnUnknownClassArrayAccess' => [
'code' => <<<'PHP'
<?php
namespace Psalmtest\Psalmtest;
use SomeMissingClass;
class Test
{
public function f(): void {
/** @var SomeMissingClass */
$result = null;
if ($result['errors'] === true) {}
}
}
PHP,
'assertions' => [],
'ignored_issues' => ['UndefinedDocblockClass'],
],
];
}

Expand Down

0 comments on commit e085b73

Please sign in to comment.