xref: /PHP-8.1/Zend/tests/bug29689.phpt (revision 2f92957f)
1--TEST--
2Bug #29689 (default value of protected member overrides default value of private)
3--FILE--
4<?php
5class foo {
6    private $foo = 'foo';
7    private $foo2 = 'foo2';
8
9    function printFoo()
10    {
11        echo __CLASS__, ': ', $this->foo, " ", $this->foo2, "\n";
12    }
13}
14
15class bar extends foo {
16    protected $foo = 'bar';
17
18    function printFoo()
19    {
20        parent::printFoo();
21        echo __CLASS__, ': ', $this->foo, " ", $this->foo2, "\n";
22    }
23}
24
25class baz extends bar {
26    protected $foo = 'baz';
27    protected $foo2 = 'baz2';
28}
29
30class bar2 extends foo {
31    function printFoo()
32    {
33        parent::printFoo();
34        echo __CLASS__, ': ', $this->foo, " ", $this->foo2, "\n";
35    }
36}
37
38class baz2 extends bar2 {
39    protected $foo = 'baz2';
40    protected $foo2 = 'baz22';
41}
42
43$bar = new bar;
44$bar->printFoo();
45echo "---baz--\n";
46$baz = new baz();
47$baz->printFoo();
48echo "---baz2--\n";
49$baz = new baz2();
50$baz->printFoo();
51?>
52--EXPECTF--
53foo: foo foo2
54bar: bar
55Warning: Undefined property: bar::$foo2 in %s on line %d
56
57---baz--
58foo: foo foo2
59bar: baz baz2
60---baz2--
61foo: foo foo2
62bar2: baz2 baz22
63