diff --git a/phpunit/src/AssignTest.php b/phpunit/src/AssignTest.php index cf44bdb5..62511fb8 100644 --- a/phpunit/src/AssignTest.php +++ b/phpunit/src/AssignTest.php @@ -11,4 +11,12 @@ class AssignTest extends \BaseTest { $this->exec('Cannot re-assign typed object `$obj1` from `stdClass` to `ArrayObject`', 're-assign-2.php'); } + + public function testStdContainerStaticClassMismatch() + { + $this->exec( + 'Cannot assign object of class `StdContainerStaticChild` to std container value of class `StdContainerStaticBase`', + 'std-container-static-class-mismatch.php' + ); + } } diff --git a/src/Php/Parser/StdContainerParser.php b/src/Php/Parser/StdContainerParser.php index 616ba7bb..708fb926 100644 --- a/src/Php/Parser/StdContainerParser.php +++ b/src/Php/Parser/StdContainerParser.php @@ -339,10 +339,9 @@ trait StdContainerParser if ($rightClass !== $class) { $this->fatalError($expr, "Cannot assign object of class `{$rightClass}` to std container value of class `{$class}`"); } - return $this->convertObjectExpr($valueExpr); } - return 'php::toObject(' . $valueExpr . ', ' . $this->getClassEntryPtr($class). ', true)'; + return 'php::toObject(' . $valueExpr . ', ' . $this->getClassEntryPtr($class) . ', true)'; } protected function parseStdMapKeyType(NodeAbstract $expr, string $owner): string