xref: /PHP-7.2/tests/classes/private_003b.phpt (revision a8d901a8)
1--TEST--
2ZE2 A private method cannot be called in a derived class
3--FILE--
4<?php
5
6class pass {
7	private function show() {
8		echo "Call show()\n";
9	}
10
11	protected function good() {
12		$this->show();
13	}
14}
15
16class fail extends pass {
17	public function ok() {
18		$this->good();
19	}
20
21	public function not_ok() {
22		$this->show();
23	}
24}
25
26$t = new fail();
27$t->ok();
28$t->not_ok(); // calling a private function
29
30echo "Done\n"; // shouldn't be displayed
31?>
32--EXPECTF--
33Call show()
34
35Fatal error: Uncaught Error: Call to private method pass::show() from context 'fail' in %s:%d
36Stack trace:
37#0 %s(%d): fail->not_ok()
38#1 {main}
39  thrown in %s on line %d
40