Skip to content

Commit

Permalink
Casting ArrayObject to array should not lead to array shape
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 15, 2025
1 parent abbae6a commit d38ed50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPStan\Type;

use ArrayAccess;
use ArrayObject;
use Closure;
use Countable;
use DateTime;
Expand Down Expand Up @@ -634,6 +635,7 @@ public function toArray(): Type

if (
!$classReflection->getNativeReflection()->isUserDefined()
|| $classReflection->is(ArrayObject::class)
|| UniversalObjectCratesClassReflectionExtension::isUniversalObjectCrate(
$reflectionProvider,
Broker::getInstance()->getUniversalObjectCratesClasses(),
Expand Down
19 changes: 19 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-12182.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php // lint >= 8.0

namespace Bug12182;

use ArrayObject;
use function PHPStan\Testing\assertType;

/**
* @extends ArrayObject<int, string>
*/
class HelloWorld extends ArrayObject
{
public function __construct(private int $a = 42) {
}
}

function (HelloWorld $hw): void {
assertType('array', (array) $hw);
};

0 comments on commit d38ed50

Please sign in to comment.