atusch.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. declare(strict_types=1);
  3. abstract class Abst {
  4. protected ?int $prop = null;
  5. abstract function toBeReplaced($tell) : string;
  6. function tell() {
  7. echo 'hoi';
  8. }
  9. /** property möglich */
  10. public string $name;
  11. function setName($name) {
  12. $this->name = $name;
  13. }
  14. function getName() {
  15. return $this->name;
  16. }
  17. public function tellme() : string {
  18. return 'I tell ' . $this->prop;
  19. }
  20. }
  21. class Normal {
  22. }
  23. class AbstChild extends Abst {
  24. public function toBeReplaced($tell) : string {
  25. return 'i fill Abst with: ' . $tell;
  26. }
  27. function tell() {
  28. echo 'tschau!';
  29. }
  30. static function create(): AbstChild {
  31. $normal = new AbstChild();
  32. $normal->prop = 1;
  33. return $normal;
  34. }
  35. }
  36. $normal = AbstChild::create();
  37. echo $normal->tellme();
  38. //die();
  39. /*
  40. class NoWorkAbstChild extends Abst {
  41. public function ifill() : string {
  42. return "i fill";
  43. }
  44. }
  45. */
  46. interface AInterface {
  47. /** Interface kann kein property haben */
  48. public function toBeReplaced() : string;
  49. }
  50. interface AOtherInterface {
  51. /** Interface kann kein property haben */
  52. public function toBeReplaced() : string;
  53. }
  54. class WithInterface implements AInterface, AOtherInterface {
  55. public function toBeReplaced(): string {
  56. return 'i fill interface';
  57. }
  58. }
  59. trait TraitOne {
  60. public function tellme() {
  61. echo 'do tell me';
  62. echo '<br>';
  63. }
  64. }
  65. trait TraitTwo {
  66. public function listenme() {
  67. echo 'i listen you';
  68. echo '<br>';
  69. }
  70. }
  71. class MyMe {
  72. use TraitOne, TraitTwo;
  73. /** wenn mehr als 1 Verrerbung nötig */
  74. }
  75. $abstchild = new AbstChild();
  76. $abstchild->setName('AbstName');
  77. echo $abstchild->toBeReplaced('gugus');
  78. echo "<br>";
  79. echo $abstchild->getName();
  80. echo "<br>";
  81. $withinterface = new WithInterface();
  82. echo $withinterface->toBeReplaced();
  83. echo "<br>";
  84. $myme = new MyMe();
  85. $myme->tellme();
  86. $myme->listenme();
  87. // $this->tagIds = array_map(fn (NewsTag $t) => $t->getId(), $news->getTags()->getArrayCopy());