Bug #77399 [Com]: __get and __set defined in traits can't access private variables from class

From: Date: Wed, 02 Jan 2019 16:10:44 +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-218752@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: mega6382 at mega6382 dot me 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: Your example doesn't show __get, it shows __test, which can be correctly used like this https://3v4l.org/M8BtH Previous Comments: ------------------------------------------------------------------------ [2019-01-02 16:05:19] levim@php.net Example on 3v4l: https://3v4l.org/97X3q ------------------------------------------------------------------------ [2019-01-02 15:50:35] cfrenette at azorus dot com Description: ------------ If you have a __get or __set method defined in a trait, they can no longer access private/protected variables defined in the class that implements them. This worked < 7.3. I wasn't able to find any information on this breaking change in the PHP 7.3 changelog. Test script: --------------- trait T { public function __test($name) { return $this->$name; } } class Test { use T; private $test = 'asdf'; } $test = new Test(); echo $test->test; Expected result: ---------------- 'asdf' is echoed. Actual result: -------------- PHP Warning: Uncaught Error: Cannot access private property Test::$test in php shell code:1 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77399&edit=1

« previous php.bugs (#218752) next »