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

Missing report on potential null property when using a dynamic child property #1499

Closed
dbu opened this issue Oct 11, 2018 · 4 comments
Closed

Comments

@dbu
Copy link

dbu commented Oct 11, 2018

Summary of a problem or a feature request

We do get a warning for the line with explicit field name in the map, but no warning when a property of a nullable property is accessed with a dynamic name.

Code snippet that reproduces the problem

class Product
{
   /**
    * @var MyMap|null
    */
   public $map;
}

class MyMap
{
    public const FIELDS = ['a', 'b'];

    public $a;

    public $b;
}

$product = new Product();
foreach (MyMap::FIELDS as $field) {
    // $product->map can be null, but we get **no** warning from phpstan
    print($product->map->$field);
}

// $product->map can be null and we do get a warning from phpstan
print($product->map->a);

Expected output

Warning that $product->map->$field could be null because Product::$map is nullable.

@dbu dbu changed the title Missing report on potential null field when using a dynamic child field Missing report on potential null property when using a dynamic child property Oct 11, 2018
@ondrejmirtes
Copy link
Member

ondrejmirtes commented Oct 11, 2018 via email

@dbu
Copy link
Author

dbu commented Oct 11, 2018

sorry, missed that. here you go: https://phpstan.org/r/d9a1196f5eea4480f3a33c48547b71f1

@ondrejmirtes
Copy link
Member

This already works thanks to phpstan/phpstan-src#348.

@github-actions
Copy link

github-actions bot commented May 2, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants