ctor_visibility.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --TEST--
  2. ZE2 A private constructor cannot be called
  3. --FILE--
  4. <?php
  5. class Test
  6. {
  7. function __construct()
  8. {
  9. echo __METHOD__ . "()\n";
  10. }
  11. }
  12. class Derived extends Test
  13. {
  14. function __construct()
  15. {
  16. echo __METHOD__ . "()\n";
  17. parent::__construct();
  18. }
  19. static function f()
  20. {
  21. new Derived;
  22. }
  23. }
  24. Derived::f();
  25. class TestPriv
  26. {
  27. private function __construct()
  28. {
  29. echo __METHOD__ . "()\n";
  30. }
  31. static function f()
  32. {
  33. new TestPriv;
  34. }
  35. }
  36. TestPriv::f();
  37. class DerivedPriv extends TestPriv
  38. {
  39. function __construct()
  40. {
  41. echo __METHOD__ . "()\n";
  42. parent::__construct();
  43. }
  44. static function f()
  45. {
  46. new DerivedPriv;
  47. }
  48. }
  49. DerivedPriv::f();
  50. ?>
  51. ===DONE===
  52. --EXPECTF--
  53. Derived::__construct()
  54. Test::__construct()
  55. TestPriv::__construct()
  56. DerivedPriv::__construct()
  57. Fatal error: Uncaught Error: Cannot call private TestPriv::__construct() in %sctor_visibility.php:%d
  58. Stack trace:
  59. #0 %s(%d): DerivedPriv->__construct()
  60. #1 %s(%d): DerivedPriv::f()
  61. #2 {main}
  62. thrown in %sctor_visibility.php on line %d