Bug #79867 [ReO->Csd]: Promoted untyped properties should get null default value
| From: | nikic@php.net | Date: | Fri, 17 Jul 2020 13:10:53 +0000 |
| Subject: | Bug #79867 [ReO->Csd]: Promoted untyped properties should get null default value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228101@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79867&edit=1
ID: 79867
Updated by: nikic@php.net
Reported by: slavcopost at gmail dot com
Summary: Promoted untyped properties should get null default
value
-Status: Re-Opened
+Status: Closed
Type: Bug
Package: Class/Object related
Operating System: *
PHP Version: 8.0.0alpha2
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=86a62eb1fcf923d7b54d63df2277d73913879d7b
Log: Fixed bug #79867
Previous Comments:
------------------------------------------------------------------------
[2020-07-16 21:03:03] slavcopost at gmail dot com
Yep, Nikita. I missed you last comment, it's exactly what I mean.
------------------------------------------------------------------------
[2020-07-16 21:00:27] slavcopost at gmail dot com
Alright, but w/o constructor promotion, when I define property it's auth initilized. I.e.
```
class A {
public $a;
}
```
does not require an additional initialization.
------------------------------------------------------------------------
[2020-07-16 20:57:33] nikic@php.net
I can see the argument for giving $a a null default value though, because that's what normally
happens with untyped properties. Right now constructor promotion gives you a property declaration
that (for untyped properties) you cannot achieve in any other way, which is certainly odd, and not
really intentional.
------------------------------------------------------------------------
[2020-07-16 20:53:04] nikic@php.net
> That has never been mandatory, has it?
No, and it's still not mandatory -- for example, you could also do a manual $this->a = 42
assignment if you like. The state of the parent class just needs to be initialized *somehow* and
parent::__construct() is the most typical and most robust way to do so.
------------------------------------------------------------------------
[2020-07-16 20:41:17] slavcopost at gmail dot com
> You are missing a parent::__construct() call.
That has never been mandatory, has it?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=79867
--
Edit this bug report at https://bugs.php.net/bug.php?id=79867&edit=1