language008b.phpt 628 B

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