DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
83 stars 10 forks source link

False positive error when accessing a class property defined as @property or @property-read #662

Closed marinaglancy closed 1 month ago

marinaglancy commented 2 months ago

Hello!

The following valid code gives an error "Member has protected visibility and is not accessible from the current context."

<?php

/**
 * @property-read int $id
 */
class MyClass {
    protected int $id;

    public function __get($name) {
        return $this->$name;
    }
}

$a = new MyClass();
echo $a->id;

php_error_protected

jakubmisek commented 2 months ago

Thank you for the test case @marinaglancy,

We'll implement better treating of property-read and property-write.

jakubmisek commented 1 month ago

Thank you @marinaglancy ,

We have fixed this issue by first respecting the @property from PHPDoc.

The fix will be available in the next update.