Skip to content

Dynamic property deprecation warning/readonly error not emitted when modifying through new ArrayObject($targetObj); #9432

Description

@TysonAndre

Description

The following code:

<?php
class MyClass {}
$c = new MyClass();
$y = new ArrayObject($c);
$y['foo'] = 'bar'; // <-- should emit deprecation warning
$c->foo2 = 2;
var_export($c); echo "\n";

readonly class ReadOnly_ {}
$r = new ReadOnly_();
$z = new ArrayObject($r);
$z['foo'] = 'bar';
var_export($r);

Resulted in this output:

Deprecated: Creation of dynamic property MyClass::$foo2 is deprecated in /usr/local/tyson/php-src/test.php on line 6
\MyClass::__set_state(array(
   'foo' => 'bar',
   'foo2' => 2,
))
\ReadOnly_::__set_state(array(
   'foo' => 'bar',
))

But I expected this output instead:

Deprecated: Creation of dynamic property MyClass::$foo is deprecated in ...
Deprecated: Creation of dynamic property MyClass::$foo2 is deprecated in ... on line 6
\MyClass::__set_state(array(
   'foo' => 'bar',
   'foo2' => 2,
))
Uncaught Error: Cannot create dynamic property ReadOnly_::$foo in ...

Discovered while reviewing #9354

PHP Version

8.2.0beta2

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions