ctor_dtor_inheritance.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --TEST--
  2. ZE2 A derived class can use the inherited constructor/destructor
  3. --SKIPIF--
  4. <?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
  5. --FILE--
  6. <?php
  7. // This test checks for:
  8. // - inherited constructors/destructors are not called automatically
  9. // - base classes know about derived properties in constructor/destructor
  10. // - base class constructors/destructors know the instanciated class name
  11. class base {
  12. public $name;
  13. function __construct() {
  14. echo __CLASS__ . "::" . __FUNCTION__ . "\n";
  15. $this->name = 'base';
  16. print_r($this);
  17. }
  18. function __destruct() {
  19. echo __CLASS__ . "::" . __FUNCTION__ . "\n";
  20. print_r($this);
  21. }
  22. }
  23. class derived extends base {
  24. public $other;
  25. function __construct() {
  26. $this->name = 'init';
  27. $this->other = 'other';
  28. print_r($this);
  29. parent::__construct();
  30. echo __CLASS__ . "::" . __FUNCTION__ . "\n";
  31. $this->name = 'derived';
  32. print_r($this);
  33. }
  34. function __destruct() {
  35. parent::__destruct();
  36. echo __CLASS__ . "::" . __FUNCTION__ . "\n";
  37. print_r($this);
  38. }
  39. }
  40. echo "Testing class base\n";
  41. $t = new base();
  42. unset($t);
  43. echo "Testing class derived\n";
  44. $t = new derived();
  45. unset($t);
  46. echo "Done\n";
  47. ?>
  48. --EXPECTF--
  49. Testing class base
  50. base::__construct
  51. base Object
  52. (
  53. [name] => base
  54. )
  55. base::__destruct
  56. base Object
  57. (
  58. [name] => base
  59. )
  60. Testing class derived
  61. derived Object
  62. (
  63. [other] => other
  64. [name] => init
  65. )
  66. base::__construct
  67. derived Object
  68. (
  69. [other] => other
  70. [name] => base
  71. )
  72. derived::__construct
  73. derived Object
  74. (
  75. [other] => other
  76. [name] => derived
  77. )
  78. base::__destruct
  79. derived Object
  80. (
  81. [other] => other
  82. [name] => derived
  83. )
  84. derived::__destruct
  85. derived Object
  86. (
  87. [other] => other
  88. [name] => derived
  89. )
  90. Done