Skip to content

InaccessibleProperty and mixed|string for a private or protected property when the class has __get() and a @mixin that declares it #14132

Closed

Description

@alies-dev

https://psalm.dev/r/b19711e6cc

What Psalm reports / does
InaccessibleProperty on lines 21 and 22, and $_p / $_q are mixed|string. Host has a private $p and a protected $q, a __get(), and @mixin Mx, where Mx has public int $p and int $q. Both reads come from outside the class.

What you expected
No issue, and int for both. Outside the class the property is not accessible, so PHP calls Host::__get(), which is what the @mixin documents as forwarding to Mx. PHPStan 2.3 resolves both reads to int without an error. This is the property counterpart of #13727, which did the same for an inaccessible method (__call() + @mixin); that case is int on psalm.dev now, only the property fetch still stops at the inaccessible declaration.

Psalm version, PHP version
psalm.dev 7.x-dev (dev-master@ce04a73), PHP 8.3

Activity

  1. psalm-github-bot commented on Nov 17, 2026

    @psalm-github-bot

    I found these snippets:

    https://psalm.dev/r/b19711e6cc
    <?php
    
    final class Mx
    {
        public int $p = 1;
        public int $q = 1;
    }
    
    /** @mixin Mx */
    final class Host
    {
        private string $p = '';
        protected string $q = '';
    
        public function __get(string $name): mixed
        {
            return null;
        }
    }
    
    $_p = (new Host())->p;
    $_q = (new Host())->q;
    /** @psalm-trace $_p */
    /** @psalm-trace $_q */
    Psalm output (using commit ce04a73):
    
    ERROR: InaccessibleProperty - 21:7 - Cannot access private property Host::$p
    
    ERROR: InaccessibleProperty - 22:7 - Cannot access protected property Host::$q
    
    INFO: Trace - 24:24 - $_p: mixed|string
    
    INFO: Trace - 24:24 - $_q: mixed|string
    
  2. changed the title [-]InaccessibleProperty and mixed|string for a private or protected property when the class has __get() and a @mixin that declares it[/-] [+]InaccessibleProperty and `mixed|string` for a private or protected property when the class has `__get()` and a `@mixin` that declares it[/+] on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions