inheritance_007.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. Ensure private methods with the same name are not checked for inheritance rules - final
  3. --FILE--
  4. <?php
  5. class A {
  6. function callYourPrivates() {
  7. $this->normalPrivate();
  8. $this->finalPrivate();
  9. }
  10. function notOverridden_callYourPrivates() {
  11. $this->normalPrivate();
  12. $this->finalPrivate();
  13. }
  14. private function normalPrivate() {
  15. echo __METHOD__ . PHP_EOL;
  16. }
  17. final private function finalPrivate() {
  18. echo __METHOD__ . PHP_EOL;
  19. }
  20. }
  21. class B extends A {
  22. function callYourPrivates() {
  23. $this->normalPrivate();
  24. $this->finalPrivate();
  25. }
  26. private function normalPrivate() {
  27. echo __METHOD__ . PHP_EOL;
  28. }
  29. final private function finalPrivate() {
  30. echo __METHOD__ . PHP_EOL;
  31. }
  32. }
  33. $a = new A();
  34. $a->callYourPrivates();
  35. $a->notOverridden_callYourPrivates();
  36. $b = new B();
  37. $b->callYourPrivates();
  38. $b->notOverridden_callYourPrivates();
  39. ?>
  40. --EXPECTF--
  41. Warning: Private methods cannot be final as they are never overridden by other classes %s
  42. Warning: Private methods cannot be final as they are never overridden by other classes %s
  43. A::normalPrivate
  44. A::finalPrivate
  45. A::normalPrivate
  46. A::finalPrivate
  47. B::normalPrivate
  48. B::finalPrivate
  49. A::normalPrivate
  50. A::finalPrivate