PHPSTORM_META does not work at all
Hi,
I tried this on 2017.3 and on the latest 2018.1 EAP (Build #PS-181.3263.18, built on January 31, 2018). I create a new empty PHP project and add exactly the three files somewhere.php, testUsage.php and .phpstorm.meta.php with the content from the documentation: https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata
Then I fix the compiler warning by implementing ServiceManager::getByPattern().
Whatever I do and change around, I can't get the metadata to be recognized. To test it, I hold the Ctrl key and hover over $getStatic, $getDynamic or $getFromArray and check the type hint there -- it's always "mixed" and never "\Exception::class" as expected.
What am I doing wrong? Or is the feature currently completely broken? There are several open issues regarding this feature, but they more seem like it doesn't work in very special situations.
The reason I'm trying to use the feature in the first place is because the Silex plugin (https://plugins.jetbrains.com/plugin/7809-silex-pimple-plugin) stopped working late last year, so I'm looking for a replacement.
Thank you
Philipp
Please sign in to leave a comment.
It's a bug, please vote: https://youtrack.jetbrains.com/issue/WI-35503
I have same issue with 2018.1 EAP
Edit: I made it work by creating '.phpstorm.meta.php' folder and my ***.meta.php files in it. Then restart PhpStorm
Please share certain meta and PHP files?
Here's what I am using:
.phpstorm.meta.php
meta_test.php
Result is:
I can confirm that moving to `.phpstorm.meta.php/sdf.meta.php` + restart solved the problem. (I also had to re-insert the `namespace PHPSTORM_META` which I had removed thinking that it might cause the issue).
Also I was able to make Eugene's example work, interestingly without the subfolder. When I copied over the original example I was using (straight from Confluence) piece by piece, it still kept working without the subfolder, except for the array-based access. Whether the config file was in the subfolder or not (I tried both with restarts), I was able to narrow it down to this one difference:
(note the commented-out instantiation; the same declaration is over in somewhere.php)
(note that array access does not work, instantiation is just before, it doesn't matter if the instantiation in somewhere.php is kept or removed)
(note that method access still works in the same situation)
---
In case someone has access to that Confluence page, please add the missing ServiceManager::getByPattern() implementation.
Some more data that may or may not have an effect: Windows 10 x64, PHP 7.1.4
> In case someone has access to that Confluence page, please add the missing ServiceManager::getByPattern() implementation.
Done.
Also, more importantly for my use case, the array-based acces does not work when the instance is defined as a member property, as in the Confluence example. I changed the original line `$worksThroughProperties = $this->serviceManager->get(Exception::class);` to `$worksThroughProperties = $this->serviceManager["Exception"];` and it stops working:
This is the use case that ultimately matters to me (and many other users who do dependency injection like this). In the same situation, the `->get()` based access works. And it knows the type of `$this->serviceManager` when I hover it or when I assign it to a local variable.