|
| 1 | +<?php |
| 2 | + |
| 3 | +class Foo |
| 4 | +{ |
| 5 | + /* testReadonlyProperty */ |
| 6 | + readonly int $readonlyProperty; |
| 7 | + /* testVarReadonlyProperty */ |
| 8 | + var readonly int $varReadonlyProperty; |
| 9 | + /* testReadonlyVarProperty */ |
| 10 | + readonly var int $testReadonlyVarProperty; |
| 11 | + /* testStaticReadonlyProperty */ |
| 12 | + static readonly int $staticReadonlyProperty; |
| 13 | + /* testReadonlyStaticProperty */ |
| 14 | + readonly static int $readonlyStaticProperty; |
| 15 | + /* testReadonlyPropertyWithoutType */ |
| 16 | + readonly $propertyWithoutType; |
| 17 | + /* testPublicReadonlyProperty */ |
| 18 | + public readonly int $publicReadonlyProperty; |
| 19 | + /* testProtectedReadonlyProperty */ |
| 20 | + protected readonly int $protectedReadonlyProperty; |
| 21 | + /* testPrivateReadonlyProperty */ |
| 22 | + private readonly int $privateReadonlyProperty; |
| 23 | + /* testPublicReadonlyPropertyWithReadonlyFirst */ |
| 24 | + readonly public int $publicReadonlyProperty; |
| 25 | + /* testProtectedReadonlyPropertyWithReadonlyFirst */ |
| 26 | + readonly protected int $protectedReadonlyProperty; |
| 27 | + /* testPrivateReadonlyPropertyWithReadonlyFirst */ |
| 28 | + readonly private int $privateReadonlyProperty; |
| 29 | + /* testReadonlyWithCommentsInDeclaration */ |
| 30 | + private /* Comment */ readonly /* Comment */ int /* Comment */ $readonlyPropertyWithCommentsInDeclaration; |
| 31 | + /* testReadonlyWithNullableProperty */ |
| 32 | + private readonly ?int $nullableProperty; |
| 33 | + /* testReadonlyNullablePropertyWithUnionTypeHintAndNullFirst */ |
| 34 | + private readonly null|int $nullablePropertyWithUnionTypeHintAndNullFirst; |
| 35 | + /* testReadonlyNullablePropertyWithUnionTypeHintAndNullLast */ |
| 36 | + private readonly int|null $nullablePropertyWithUnionTypeHintAndNullLast; |
| 37 | + /* testReadonlyPropertyWithArrayTypeHint */ |
| 38 | + private readonly array $arrayProperty; |
| 39 | + /* testReadonlyPropertyWithSelfTypeHint */ |
| 40 | + private readonly self $selfProperty; |
| 41 | + /* testReadonlyPropertyWithParentTypeHint */ |
| 42 | + private readonly parent $parentProperty; |
| 43 | + /* testReadonlyPropertyWithFullyQualifiedTypeHint */ |
| 44 | + private readonly \stdClass $propertyWithFullyQualifiedTypeHint; |
| 45 | + |
| 46 | + /* testReadonlyIsCaseInsensitive */ |
| 47 | + public ReAdOnLy string $caseInsensitiveProperty; |
| 48 | + |
| 49 | + /* testReadonlyConstructorPropertyPromotion */ |
| 50 | + public function __construct(private readonly bool $constructorPropertyPromotion) |
| 51 | + { |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +$anonymousClass = new class () { |
| 56 | + /* testReadonlyPropertyInAnonymousClass */ |
| 57 | + public readonly int $property; |
| 58 | +}; |
| 59 | + |
| 60 | +class ClassName { |
| 61 | + /* testReadonlyUsedAsClassConstantName */ |
| 62 | + const READONLY = 'readonly'; |
| 63 | + |
| 64 | + /* testReadonlyUsedAsMethodName */ |
| 65 | + public function readonly() { |
| 66 | + // Do something. |
| 67 | + |
| 68 | + /* testReadonlyUsedAsPropertyName */ |
| 69 | + $this->readonly = 'foo'; |
| 70 | + |
| 71 | + /* testReadonlyPropertyInTernaryOperator */ |
| 72 | + $isReadonly = $this->readonly ? true : false; |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +/* testReadonlyUsedAsFunctionName */ |
| 77 | +function readonly() |
| 78 | +{ |
| 79 | +} |
| 80 | + |
| 81 | +/* testReadonlyUsedAsNamespaceName */ |
| 82 | +namespace Readonly; |
| 83 | +/* testReadonlyUsedAsPartOfNamespaceName */ |
| 84 | +namespace My\Readonly\Collection; |
| 85 | +/* testReadonlyAsFunctionCall */ |
| 86 | +$var = readonly($a, $b); |
| 87 | +/* testClassConstantFetchWithReadonlyAsConstantName */ |
| 88 | +echo ClassName::READONLY; |
| 89 | + |
| 90 | +/* testParseErrorLiveCoding */ |
| 91 | +// This must be the last test in the file. |
| 92 | +readonly |
0 commit comments