PHP8_2.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. --TEST--
  2. PHP 8.2 test.
  3. --RULESET--
  4. {
  5. "@PhpCsFixer": true,
  6. "@PHP82Migration": true
  7. }
  8. --REQUIREMENTS--
  9. {"php": 80200}
  10. --EXPECT--
  11. <?php
  12. // https://wiki.php.net/rfc/readonly_classes
  13. final readonly class Foo
  14. {
  15. public string $prop;
  16. }
  17. // https://wiki.php.net/rfc/fetch_property_in_const_expressions
  18. enum A: string
  19. {
  20. case B = 'B';
  21. public const C = [self::B->name => self::B->value];
  22. public const D = self::B?->value;
  23. }
  24. #[Attr(A::B->name)]
  25. class E {}
  26. // https://wiki.php.net/rfc/null-false-standalone-types
  27. class FalseNull
  28. {
  29. private false $a = false;
  30. private null $b = null;
  31. public function __construct(
  32. private false $falsy = false,
  33. private null $nully = null
  34. ) {}
  35. public function falsy(): false
  36. {
  37. return $this->falsy;
  38. }
  39. public function nully(): null
  40. {
  41. return $this->nully;
  42. }
  43. public function setAB(false $a, null $b): void
  44. {
  45. $this->a = $a;
  46. $this->b = $b;
  47. }
  48. }
  49. function falsyNull(null $n, false $f): ?false {}
  50. array_filter([], fn (null $n) => null === $n);
  51. array_filter([], fn (false $n) => false === $n);
  52. // https://wiki.php.net/rfc/true-type
  53. class TrueType
  54. {
  55. private true $a = true;
  56. public function __construct(
  57. private true $havingABud = true
  58. ) {}
  59. public function havingABud(): true
  60. {
  61. return $this->havingABud;
  62. }
  63. public function setA(true $a): void
  64. {
  65. $this->a = $a;
  66. }
  67. }
  68. function truish(true $true): true
  69. {
  70. return $true;
  71. }
  72. array_filter([], fn (true $n) => true === $n);
  73. // https://wiki.php.net/rfc/constants_in_traits
  74. trait WithConstants
  75. {
  76. public const ONE = 'one';
  77. protected const TWO = 'two';
  78. private const THREE = 'three';
  79. }
  80. // https://wiki.php.net/rfc/dnf_types
  81. function generateSlug(null|(HasId&HasTitle) $post)
  82. {
  83. throw new Exception('not implemented');
  84. }
  85. --INPUT--
  86. <?php
  87. // https://wiki.php.net/rfc/readonly_classes
  88. READONLY final class Foo
  89. {
  90. public string $prop;
  91. }
  92. // https://wiki.php.net/rfc/fetch_property_in_const_expressions
  93. enum A: string
  94. {
  95. case B = 'B';
  96. const C = [self::B -> name => self::B->value];
  97. const D = self::B ?-> value;
  98. }
  99. #[Attr(A::B -> name)]
  100. class E
  101. {
  102. }
  103. // https://wiki.php.net/rfc/null-false-standalone-types
  104. class FalseNull {
  105. private FALSE $a = FALSE;
  106. private NULL $b = NULL;
  107. public function __construct(
  108. private FALSE $falsy = FALSE,
  109. private NULL $nully = NULL
  110. ) {
  111. }
  112. public function falsy() : FALSE
  113. {
  114. return $this -> falsy;
  115. }
  116. public function nully() : NULL
  117. {
  118. return $this -> nully;
  119. }
  120. public function setAB(FALSE $a, NULL $b): void
  121. {
  122. $this->a = $a;
  123. $this->b = $b;
  124. }
  125. }
  126. function falsyNull (NULL $n, FALSE $f): NULL|FALSE
  127. {
  128. }
  129. array_filter([], fn (NULL $n) => NULL === $n);
  130. array_filter([], fn (FALSE $n) => FALSE === $n);
  131. // https://wiki.php.net/rfc/true-type
  132. class TrueType {
  133. private TRUE $a = TRUE;
  134. public function __construct(
  135. private TRUE $havingABud = TRUE
  136. ) {
  137. }
  138. public function havingABud() : TRUE
  139. {
  140. return $this -> havingABud;
  141. }
  142. public function setA(TRUE $a): void
  143. {
  144. $this->a = $a;
  145. }
  146. }
  147. function truish (TRUE $true) : TRUE
  148. {
  149. return $true;
  150. }
  151. array_filter([], fn (TRUE $n) => TRUE === $n);
  152. // https://wiki.php.net/rfc/constants_in_traits
  153. trait WithConstants {
  154. public const ONE = 'one';
  155. protected const TWO = 'two';
  156. private const THREE = 'three';
  157. }
  158. // https://wiki.php.net/rfc/dnf_types
  159. function generateSlug((HasTitle&HasId)|null $post)
  160. {
  161. throw new \Exception('not implemented');
  162. }