Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoInterfaceProperties triggers when checking if property exists on an object #2206

Open
pamil opened this issue Oct 4, 2019 · 0 comments
Open
Labels

Comments

@pamil
Copy link

pamil commented Oct 4, 2019

Runnable example: https://psalm.dev/r/de34c21744

Code from the example:

<?php
  
interface SomeInterface
{
  public function doSomething(): void;  
}

final class FirstImplementation implements SomeInterface
{
  /** @var int */
  public $someField = 42;
  
  public function doSomething(): void {}
}

function magic(SomeInterface $x): void {
  if (!property_exists(get_class($x), 'someField')) {
    return;  
  }
  
  if (!isset($x->someField)) {
    return;
  }
  
  $x->someField = 0;
};

$x = new FirstImplementation();
magic($x);
assert($x->someField === 0);

It should be possible to access the property after checking that it exists.

Using both property_exists and isset to prove they both don't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants