Bug #78455 [Com]: Access violation of private trait members
| From: | developmenthero at gmail dot com | Date: | Sun, 25 Aug 2019 00:03:15 +0000 |
| Subject: | Bug #78455 [Com]: Access violation of private trait members | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222398@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78455&edit=1
ID: 78455
Comment by: developmenthero at gmail dot com
Reported by: developmenthero at gmail dot com
Summary: Access violation of private trait members
Status: Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: Windows 10
PHP Version: 7.3.8
Block user comment: N
Private report: N
New Comment:
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);
Previous Comments:
------------------------------------------------------------------------
[2019-08-24 23:20:25] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
> Prior to v7.3, "A::__set()" would be triggered here.
Nope. https://3v4l.org/5XSGH
------------------------------------------------------------------------
[2019-08-24 23:17:14] 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());
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78455&edit=1