xref: /PHP-8.3/Zend/tests/bug29674.phpt (revision f8d79582)
1--TEST--
2Bug #29674 (inherited method doesn't have access to private variables of the derived class)
3--FILE--
4<?php
5
6class BaseClass
7{
8    private $private_base = "Base";
9
10    function printVars ()
11    {
12        var_dump($this->private_base);
13        var_dump($this->private_child);
14    }
15}
16
17class ChildClass extends BaseClass
18{
19    private $private_child = "Child";
20}
21
22echo "===BASE===\n";
23$obj = new BaseClass;
24$obj->printVars();
25
26echo "===CHILD===\n";
27$obj = new ChildClass;
28$obj->printVars();
29
30?>
31===DONE===
32--EXPECTF--
33===BASE===
34string(4) "Base"
35
36Warning: Undefined property: BaseClass::$private_child in %s on line %d
37NULL
38===CHILD===
39string(4) "Base"
40
41Fatal error: Uncaught Error: Cannot access private property ChildClass::$private_child in %sbug29674.php:%d
42Stack trace:
43#0 %s(%d): BaseClass->printVars()
44#1 {main}
45  thrown in %sbug29674.php on line %d
46