property008.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --TEST--
  2. Handling of private fields with traits needs to have same semantics as with normal inheritance.
  3. --FILE--
  4. <?php
  5. class BaseWithPropA {
  6. private $hello = 0;
  7. }
  8. // This is how privates are handled in normal inheritance
  9. class SubclassClassicInheritance extends BaseWithPropA {
  10. private $hello = 0;
  11. }
  12. // And here, we need to make sure, that the traits behave the same
  13. trait AHelloProperty {
  14. private $hello = 0;
  15. }
  16. class BaseWithTPropB {
  17. use AHelloProperty;
  18. }
  19. class SubclassA extends BaseWithPropA {
  20. use AHelloProperty;
  21. }
  22. class SubclassB extends BaseWithTPropB {
  23. use AHelloProperty;
  24. }
  25. $classic = new SubclassClassicInheritance;
  26. var_dump($classic);
  27. $a = new SubclassA;
  28. var_dump($a);
  29. $b = new SubclassB;
  30. var_dump($b);
  31. ?>
  32. --EXPECT--
  33. object(SubclassClassicInheritance)#1 (2) {
  34. ["hello":"BaseWithPropA":private]=>
  35. int(0)
  36. ["hello":"SubclassClassicInheritance":private]=>
  37. int(0)
  38. }
  39. object(SubclassA)#2 (2) {
  40. ["hello":"BaseWithPropA":private]=>
  41. int(0)
  42. ["hello":"SubclassA":private]=>
  43. int(0)
  44. }
  45. object(SubclassB)#3 (2) {
  46. ["hello":"BaseWithTPropB":private]=>
  47. int(0)
  48. ["hello":"SubclassB":private]=>
  49. int(0)
  50. }