xref: /PHP-8.2/Zend/tests/traits/language008b.phpt (revision d30cd7d7)
1--TEST--
2Visibility can be changed with the as aliasing construct as well.
3--FILE--
4<?php
5error_reporting(E_ALL);
6
7trait HelloWorld {
8   public function sayHello() {
9     echo 'Hello World!';
10   }
11}
12
13class MyClass {
14   use HelloWorld { sayHello as private sayHelloWorld; }
15
16   public function callPrivateAlias() {
17      $this->sayHelloWorld();
18   }
19}
20
21$o = new MyClass();
22$o->sayHello();
23$o->callPrivateAlias();
24$o->sayHelloWorld();
25
26
27?>
28--EXPECTF--
29Hello World!Hello World!
30Fatal error: Uncaught Error: Call to private method MyClass::sayHelloWorld() from global scope in %s:%d
31Stack trace:
32#0 {main}
33  thrown in %s on line %d
34