|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-01-02 15:50 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 00:00:02 2025 UTC |
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; } //