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

2
6 comments
Avatar
Permanently deleted user

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

1

Please share certain meta and PHP files?

Here's what I am using:

.phpstorm.meta.php

<?php
namespace PHPSTORM_META {

override(\ServiceLocatorInterface::getByPattern(0),
map([
'' => '@Iterator|\Iterator',
]));

}

meta_test.php

<?php

interface ServiceLocatorInterface {
function get( $name ); //You call this to get your helper depending on argument

function getByPattern( $name );
}

class ServiceManager implements ServiceLocatorInterface {
function get( $name ) {
return new $name; //simplest test example implementation
}

function getByPattern($name) {
}
}

$byPattern = (new ServiceManager())->getByPattern("Seekable" /*Iterator*/);
 

Result is:


0
Avatar
Permanently deleted user

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:

  • When the `$serviceManager = new ServiceManager();` variable is declared in another file and not in the same file where it's used (like in the Confluence example), the array-based access (`$serviceManager["special"]`) works as expected.

(note the commented-out instantiation; the same declaration is over in somewhere.php)

  • When the `$serviceManager = new ServiceManager();` is declared (using the exact same code) in the same file as where it's used (i.e. starting from the Confluence example, you copy/cut and paste this line from `somewhere.php` into `testUsage.php`, then it does not work -- even though it's declared just 1-2 lines beforehand.

(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

1

> In case someone has access to that Confluence page, please add the missing ServiceManager::getByPattern() implementation.

Done.

0
Avatar
Permanently deleted user

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.

0

Please sign in to leave a comment.