xref: /PHP-8.3/tests/classes/protected_001b.phpt (revision d30cd7d7)
1--TEST--
2ZE2 A protected method can only be called inside the class
3--FILE--
4<?php
5
6class pass {
7    protected function fail() {
8        echo "Call fail()\n";
9    }
10
11    public function good() {
12        $this->fail();
13    }
14}
15
16$t = new pass();
17$t->good();
18$t->fail();// must fail because we are calling from outside of class pass
19
20echo "Done\n"; // shouldn't be displayed
21?>
22--EXPECTF--
23Call fail()
24
25Fatal error: Uncaught Error: Call to protected method pass::fail() from global scope in %s:%d
26Stack trace:
27#0 {main}
28  thrown in %s on line %d
29