xref: /PHP-8.4/Zend/tests/bug37212.phpt (revision a555cc0b)
1--TEST--
2Bug #37212 (Access to protected property of common base class)
3--FILE--
4<?php
5
6class A
7{
8    protected $value;
9
10    public function __construct($val)
11    {
12        $this->value = $val;
13    }
14
15    protected function getValue()
16    {
17        return $this->value;
18    }
19}
20
21class B extends A
22{
23    public function copyValue($obj)
24    {
25        $this->value = $obj->getValue();
26        $this->value = $obj->value; // value defined in common base class
27    }
28}
29class C extends A {}
30
31$B = new B("B");
32var_dump($B);
33$C = new C("C");
34var_dump($C);
35
36$B->copyValue($C);
37
38var_dump($B);
39
40?>
41--EXPECTF--
42object(B)#%d (1) {
43  ["value":protected]=>
44  string(1) "B"
45}
46object(C)#%d (1) {
47  ["value":protected]=>
48  string(1) "C"
49}
50object(B)#%d (1) {
51  ["value":protected]=>
52  string(1) "C"
53}
54