Re: Constructor promoted property and default value

From: Date: Mon, 23 Oct 2023 16:11:54 +0000
Subject: Re: Constructor promoted property and default value
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-121449@lists.php.net to get a copy of this message
> If I understand your use case properly, you should be confused by properties with default > values that are not constructor-promoted as well ? Am I wrong ? In this case, your problem is not > with promoted properties ? If we specify it the way you say, the initial values ​​of the constructor arguments will be available even when the constructor is not called. ``` class Foo { public function __construct() { } } $foo = serialize(new Foo()); // save to redis ---- update ---- class Foo { public function __construct( public $val = 'abc' ) { } } $foo = unserialize($redis_foo); var_dump($foo->val); // string(3) "abc" // Doesn't it look like the constructor is being called? ``` Such behavior felt a little counterintuitive. Regards. Saki

« previous php.internals (#121449) next »