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

Fix awkward instanceof && not null property #4

Closed
muglug opened this issue Dec 3, 2016 · 1 comment
Closed

Fix awkward instanceof && not null property #4

muglug opened this issue Dec 3, 2016 · 1 comment

Comments

@muglug
Copy link
Collaborator

muglug commented Dec 3, 2016

Given

<?php

class A {
  public function hello() {
    return 'hello';
  }
}

class B {
}

class C extends B {
  /** @var A|null */
  public $foo;
}

$maybe_c = rand(0, 10) ? new C() : new B();

,

if (!$maybe_c instanceof C || !$maybe_c->foo) {
  throw new \Exception('OK');
}

echo $maybe_c->foo->hello(); 

fails but

if (!$maybe_c instanceof C) {
  throw new \Exception('OK');
}

if (!$maybe_c->foo) {
  throw new \Exception('OK');
}

echo $maybe_c->foo->hello(); 

passes (even though they're functionally the same

@muglug
Copy link
Collaborator Author

muglug commented Dec 9, 2016

Fixed in 0675e33

@muglug muglug closed this as completed Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant