PHP8_3.test 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. --TEST--
  2. PHP 8.3 test.
  3. @TODO Fix whitespace inside dynamic const fetch, e.g. `Foo::{ $bar }`
  4. @TODO Fix whitespace between const type and const name, e.g. `public const string TEST = 'Test1';`
  5. --RULESET--
  6. {
  7. "@PhpCsFixer": true,
  8. "@PHP83Migration": true
  9. }
  10. --REQUIREMENTS--
  11. {"php": 80300}
  12. --EXPECT--
  13. <?php
  14. // https://wiki.php.net/rfc/arbitrary_static_variable_initializers
  15. function foo(int $j)
  16. {
  17. static $i = bar($j * $j);
  18. }
  19. // https://wiki.php.net/rfc/dynamic_class_constant_fetch
  20. class Foo
  21. {
  22. public const BAR = 'bar';
  23. }
  24. $bar = 'BAR';
  25. function bar(): string
  26. {
  27. return 'BAR';
  28. }
  29. $baz = ['bar' => ['bar' => 'BAR']];
  30. echo Foo::{$bar};
  31. echo Foo::{bar()};
  32. echo Foo::{$baz['bar']['bar']};
  33. // https://wiki.php.net/rfc/typed_class_constants
  34. enum E
  35. {
  36. public const string TEST = 'Test1';
  37. }
  38. trait T
  39. {
  40. public const string TEST = E::TEST;
  41. }
  42. interface I
  43. {
  44. public const string TEST = E::TEST;
  45. }
  46. class Foo implements I
  47. {
  48. use T;
  49. public const string TEST = E::TEST;
  50. }
  51. class Bar extends Foo
  52. {
  53. public const string TEST = 'Test2';
  54. }
  55. // https://www.php.net/manual/en/migration83.new-features.php#migration83.new-features.core.readonly-modifier-improvements
  56. $a = new readonly class {};
  57. --INPUT--
  58. <?php
  59. // https://wiki.php.net/rfc/arbitrary_static_variable_initializers
  60. function foo( int $j ) {
  61. static $i = bar ( $j * $j ) ;
  62. }
  63. // https://wiki.php.net/rfc/dynamic_class_constant_fetch
  64. class Foo {
  65. const BAR = 'bar';
  66. }
  67. $bar = 'BAR';
  68. function bar(): string { return 'BAR'; }
  69. $baz = ['bar' => ['bar' => 'BAR']];
  70. echo Foo :: {$bar};
  71. echo Foo :: {bar ( )};
  72. echo Foo :: {$baz [ 'bar' ] [ 'bar' ]};
  73. // https://wiki.php.net/rfc/typed_class_constants
  74. enum E {
  75. const StRiNg TEST = "Test1";
  76. }
  77. trait T {
  78. const STRING TEST = E::TEST;
  79. }
  80. interface I {
  81. const StrinG TEST = E::TEST;
  82. }
  83. class Foo implements I {
  84. use T;
  85. const strIng TEST = E::TEST;
  86. }
  87. class Bar extends Foo {
  88. const
  89. string TEST = "Test2";
  90. }
  91. // https://www.php.net/manual/en/migration83.new-features.php#migration83.new-features.core.readonly-modifier-improvements
  92. $a = New ReadOnly CLASS
  93. {
  94. };