note 127493 added to language.oop5.decon
| From: | ziggy at start dot dust | Date: | Tue, 16 Aug 2022 09:04:05 +0000 |
| Subject: | note 127493 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219431@lists.php.net to get a copy of this message | ||
Please note that constructor argument promotion is kind of half-baked (at least as of 8.1 and it
does not look to be changed in 8.2) and you are not allowed to reuse promoted argument with other
promoted arguments. For example having "old style" constructor:
<?php
public function __construct(protected string $val, protected Foo $foo = null) {
$this->val = $val;
$this->foo = $foo ?? new Foo($val);
}
?>
you will not be able to use argument promotion like this:
<?php
public function __construct(protected string $val, protected Foo $foo = new Foo($val)) {}
?>
nor
<?php
public function __construct(protected string $val, protected Foo $foo = new Foo($this->val)) {}
?>
as in both cases you will face "PHP Fatal error: Constant expression contains invalid
operations".
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.173 (proxied: 2a00:f41:388a:319a:1c64:474b:77fb:ab08)
----
Manual Page -- https://php.net/manual/en/language.oop5.decon.php
Edit -- https://main.php.net/note/edit/127493
Del: integrated -- https://main.php.net/note/delete/127493/integrated
Del: useless -- https://main.php.net/note/delete/127493/useless
Del: bad code -- https://main.php.net/note/delete/127493/bad+code
Del: spam -- https://main.php.net/note/delete/127493/spam
Del: non-english -- https://main.php.net/note/delete/127493/non-english
Del: in docs -- https://main.php.net/note/delete/127493/in+docs
Del: other reasons-- https://main.php.net/note/delete/127493
Reject -- https://main.php.net/note/reject/127493
Search -- https://main.php.net/manage/user-notes.php