Skip to content
Permalink
Browse files

Add an example on how to use `@psalm-immutable` annotation with an an…

…onymous class (#2544)

Related to #2543
  • Loading branch information
LeSuisse authored and muglug committed Jan 2, 2020
1 parent de0fad2 commit 88c496121e2f6ce412b01aa7280d96b8a198187c
Showing with 38 additions and 0 deletions.
  1. +38 −0 docs/annotating_code/supported_annotations.md
@@ -257,6 +257,44 @@ class E {

Used to annotate a class where every property is treated by consumers as `@psalm-readonly` and every instance method is treated as `@psalm-mutation-free`.

```php
/**
* @psalm-immutable
*/
abstract class Foo
{
public string $baz;
abstract public function bar(): int;
}
/**
* @psalm-immutable
*/
final class ChildClass extends Foo
{
public function __construct(string $baz)
{
$this->baz = $baz;
}
public function bar(): int
{
return 0;
}
}
$anonymous = new /** @psalm-immutable */ class extends Foo
{
public string $baz = "B";
public function bar(): int
{
return 1;
}
};
```

### `@psalm-pure`

Used to annotate a [pure function](https://en.wikipedia.org/wiki/Pure_function) - one whose output is just a function of its input.

0 comments on commit 88c4961

Please sign in to comment.
You can’t perform that action at this time.