I'm restricting read/write to selected object properties by setting them to private/protected and only return/update them via magic methods __get()
/__set()
. Since intellisense don't know my intention here, I wrote some phpDoc to indicate which properties are able to be read/written. Please the the example bellow.
<?php
/**
* Summary of SampleClass
*
* @property-read int $id
* @property-write string $name
*/
class SampleClass {
protected int $id;
protected string $name;
public function __get($name) {
// Some magic goes here...
}
public function __set($name, $value) {
// Some magic goes here...
}
}
$a = new SampleClass;
$a -> id;
$a -> name = "Hello World";
Which the example above, intellisense should not show any error, but instead I got this error in the bellow screenshot. My extension version is 1.51.16078 and I'm using php 8.1.