Bug #78904 [Csd]: Uninitialized property triggers __get()

From: Date: Fri, 17 Jan 2020 10:04:24 +0000
Subject: Bug #78904 [Csd]: Uninitialized property triggers __get()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224948@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
 Updated by:         nikic@php.net
 Reported by:        public at grik dot net
 Summary:            Uninitialized property triggers __get()
 Status:             Closed
 Type:               Bug
 Package:            *General Issues
 PHP Version:        7.4.0
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

@andrzej: Lazy property initialization is still supported and used by ProxyManager for example. To
lazily initialize both typed and untyped properties, you must unset() them in the constructor.


Previous Comments:
------------------------------------------------------------------------
[2020-01-17 09:57:06] andrzej dot heczko at gmail dot com

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.

------------------------------------------------------------------------
[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.

------------------------------------------------------------------------


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


Thread (14 messages)

« previous php.bugs (#224948) next »