How to expose a read-only integer to the outside class while being writable inside a class with PHP

1 Answer

0 votes
class Test
{
    private int $x = 1000; // Explicitly specifying the type

    public function getX(): int {
        return $this->x;
    }
}

$T = new Test();

echo $T->getX(); 




/*
run:

43

*/

 



answered May 21, 2025 by avibootz
...