Skip to content

new ArrayObject($targetObject) allows setting typed properties to invalid types #9434

Description

@TysonAndre

Description

The following code:

<?php
class C {
    public int $intProp;
}
$c = new C();
$a = new ArrayObject($c);
$a['intProp'] = [];
var_export($c);

// Alternate snippet that would be an Uncaught TypeError: Cannot assign array to property C::$intProp of type int
// unset($c->intProp);
// $c->intProp = [];

Resulted in this output:

\C::__set_state(array(
   'intProp' => 
  array (
  ),
))

But I expected this output instead:

Uncaught TypeError: Cannot assign array to property C::$intProp of type int

Related to #9432
Discovered while reviewing #9354

PHP Version

PHP 7.4+

Operating System

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions