Bug #77399 [Com]: __get and __set defined in traits can't access private variables from class
| From: | cfrenette at azorus dot com | Date: | Wed, 02 Jan 2019 20:31:22 +0000 |
| Subject: | Bug #77399 [Com]: __get and __set defined in traits can't access private variables from class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218764@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77399&edit=1
ID: 77399
Comment by: cfrenette at azorus dot com
Reported by: cfrenette at azorus dot com
Summary: __get and __set defined in traits can't access
private variables from class
Status: Open
Type: Bug
Package: *General Issues
Operating System: Windows 10 18305
PHP Version: 7.3.0
Block user comment: N
Private report: N
New Comment:
Okay, here we go, found a simple reproduction.
https://3v4l.org/0OAve
Looks like in 7.3, the __set method from the trait isn't being called at all.
Previous Comments:
------------------------------------------------------------------------
[2019-01-02 19:07:41] spam2 at rhsoft dot net
what about provide a tiny *standalone* but *complete* reproducer starting with <?php and ending
with ?>
------------------------------------------------------------------------
[2019-01-02 19:05:12] corey at narwhunderful dot com
I think it's worth noting that if I change the name of the private variable to something
different than the magic method name, it starts working.
e.g.
// This does not work
private $test;
protected function getTest() {
return $this->test;
}
//
// This DOES work
private $_test;
protected function getTest() {
return $this->_test;
}
//
------------------------------------------------------------------------
[2019-01-02 18:59:50] cfrenette at azorus dot com
My mistake, I did mistype the code I was using to reproduce this in immediate mode, and using the
correct method name does indeed fix it.
However, in my actual code that is using the magic methods, it's not working on 7.3, but is
working on 7.2 and 7.1. You can see a failing build here: https://travis-ci.org/BapCat/Propifier/builds/474430892
Code is here: https://github.com/BapCat/Propifier/blob/master/src/PropifierTrait.php#L206
Failing test is here: https://github.com/BapCat/Propifier/blob/master/tests/PropifierTraitTest.php#L25
The trait takes protected methods (like getXyz() and/or setXyz()) and turns them into strongly-typed
properties (like $obj->xyz).
I don't believe it's a bug in the code, since it runs normally on 7.1/7.2 (and was running
fine on earlier versions before adding type hints, etc.)
------------------------------------------------------------------------
[2019-01-02 16:10:58] danack@php.net
Hi,
I'm quite confused by your example, in particular:
i) Your code doesn't include __get, which is what I think you were reporting.
ii) The code in your example works the same on 7.3 as previous versions of PHP - https://3v4l.org/97X3q
iii) What I think you're reporting, does work on 7.3: https://3v4l.org/5p6u3
Please can you clarify what you're reporting.
------------------------------------------------------------------------
[2019-01-02 16:10:43] mega6382 at mega6382 dot me
Your example doesn't show __get, it shows __test, which can be correctly used like this https://3v4l.org/M8BtH
------------------------------------------------------------------------
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=77399
--
Edit this bug report at https://bugs.php.net/bug.php?id=77399&edit=1