Skip to content
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

readonly properties in constructor #174

Open
leongrdic opened this issue Apr 26, 2022 · 3 comments
Open

readonly properties in constructor #174

leongrdic opened this issue Apr 26, 2022 · 3 comments

Comments

@leongrdic
Copy link

PHP version 8.1.5

following code

class A {
    public function __construct(
        public readonly string $prop,
    )
    {
    }
}

$a = new A('some value');
$b = \DeepCopy\deep_copy($a);

throws following:

PHP Fatal error:  Uncaught Error: Cannot modify readonly property A::$prop in .../vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:257
Stack trace:
#0 .../vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php(257): ReflectionProperty->setValue()
#1 .../vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php(213): DeepCopy\DeepCopy->copyObjectProperty()
#2 .../vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php(149): DeepCopy\DeepCopy->copyObject()
#3 .../vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php(94): DeepCopy\DeepCopy->recursiveCopy()
#4 .../vendor/myclabs/deep-copy/src/DeepCopy/deep_copy.php(18): DeepCopy\DeepCopy->copy()
#5 .../test.php(57): DeepCopy\deep_copy()
#6 {main}
  thrown in .../vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php on line 257
@roxblnfk
Copy link

are there any updates?

@mnapoli
Copy link
Member

mnapoli commented Sep 13, 2022

@roxblnfk feel free to send a PR, I don't think anyone else has contributed a fix yet.

@iGrog
Copy link

iGrog commented Sep 7, 2023

Any news on the matter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants