|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-08-24 23:17 UTC] developmenthero at gmail dot com
Description:
------------
Private members of traits are (at least) since v7.3.7 accessible from within "using" classes now.
Unfortunately this broke triggering __get() and __set() methods within traits.
Test script:
---------------
trait A {
private $value = 1;
public function getValue() {
return $this->value;
}
public function __set($name, $val) {
var_dump($name, $val);
}
}
class B {
use A;
public function setValue($value) {
// Prior to v7.3, "A::__set()" would be triggered here.
$this->value = $value;
}
}
$B = new B();
var_dump($B->getValue());
$B->setValue(12);
var_dump($B->getValue());
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 20:00:01 2025 UTC |
Interestingly i just realized that __get won't be called from inside child-classes, since i upgraded from 7.2.4 to 7.3.7(now /.3.8). But clarify: Shouldn't it be possible to access private fields of traits from a different scope than the trait itself? Pardon me, i stripped down the snippet: <?php declare(strict_types=1); trait A { private $value = 1; public function getValue() { return $this->value; } public function __get($name) { return "hello world"; } } class B { use A; public function getValue() { return $this->value; } } $B = new B(); var_dump($B->getValue()); var_dump($B->value);