Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TysonAndre opened this issue Aug 26, 2022 · 2 comments · May be fixed by #12037
Open

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

TysonAndre opened this issue Aug 26, 2022 · 2 comments · May be fixed by #12037

Comments

@TysonAndre
Copy link
Contributor

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

@cmb69
Copy link
Member

cmb69 commented Aug 26, 2022

https://3v4l.org/7vGT3 – ugh.

@Akenndy

This comment was marked as spam.

iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 2, 2022
* Property type checks
* Undeclared property warning
* Readonly property

Make ArrayObject use the write_property handler instead of modifying the
underlying property table. This also means that we're now calling __set
when the property is not declared and __set is declared.

Fixes phpGH-9434
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Sep 2, 2022
* Property type checks
* Undeclared property warning
* Readonly property

Make ArrayObject use the write_property handler instead of modifying the
underlying property table. This also means that we're now calling __set
when the property is not declared and __set is declared.

Fixes phpGH-9434
@Girgias Girgias linked a pull request Aug 23, 2023 that will close this issue
@Girgias Girgias linked a pull request Aug 23, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants