Bug #78904 [Com]: Uninitialized property triggers __get()
| From: | andrzej dot heczko at gmail dot com | Date: | Fri, 17 Jan 2020 09:57:06 +0000 |
| Subject: | Bug #78904 [Com]: Uninitialized property triggers __get() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224945@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78904&edit=1
ID: 78904
Comment by: andrzej dot heczko at gmail dot com
Reported by: public at grik dot net
Summary: Uninitialized property triggers __get()
Status: Closed
Type: Bug
Package: *General Issues
PHP Version: 7.4.0
Block user comment: N
Private report: N
New Comment:
I was experimenting with this behavior to allow lazy property initialization. For instance I can
lazy load services in controllers. Now there is no other option, how to allow lazy initialize
property. I have to stick back to annotations and dynamic properties.
You could add another magic method to allow that e.g. "__init",
"__initProperty", "__getStrict", "__getTyped", etc. which would
respect access modifiers.
You can see all my efforts in composer package bigbit/oddin.
Version 1.* is using annotations and dynamic properties, version 2.* is using typed properties and
__get.
Previous Comments:
------------------------------------------------------------------------
[2019-12-09 07:43:01] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=84354c62b37a56816a695b18ebd898f9703a9ad2
Log: Fixed bug #78904: Don't call any magic for uninitialized typed properties
------------------------------------------------------------------------
[2019-12-06 15:32:10] public at grik dot net
Thank you. Sorry for filling this ticket up improperly, I did not expect attention.
------------------------------------------------------------------------
[2019-12-06 14:47:19] nikic@php.net
The following pull request has been associated:
Patch Name: Also don't call other magic for uninitialized typed properties
On GitHub: https://github.com/php/php-src/pull/4974
Patch: https://github.com/php/php-src/pull/4974.patch
------------------------------------------------------------------------
[2019-12-06 14:35:10] nikic@php.net
> It would make sense to show a compile-time warning/notice for typed property declarations
> without initial value. Consider it for a later version, please.
Certainly not. There is nothing wrong with a property that does not have an initial value. In fact
nearly all properties shouldn't have one, as most properties get initialized based on
constructor arguments.
Based on preliminary discussion we might change __get() behavior, so I'm reopening this.
I'll prepare a patch asap.
------------------------------------------------------------------------
[2019-12-06 14:19:42] public at grik dot net
It would make sense to show a compile-time warning/notice for typed property declarations without
initial value. Consider it for a later version, please.
If it is not possible, consider adding the way to check if the property is initialized, so framework
authors could process this state in magic getters properly.
------------------------------------------------------------------------
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=78904
--
Edit this bug report at https://bugs.php.net/bug.php?id=78904&edit=1