Sorry for the weird title wording.
I want a class to have a property that can be viewed but not changed, and I want to set it inside a function.
Like this:
class Foo {
public int $bar;
public function __construct(int $input) {
if ($input < 4) {
$this->bar = $input;
}
}
}
$foo = new Foo(2);
echo $foo->bar; // Returns 2
$foo->bar = 1 // Gives error