skip to Main Content

I downloaded the OpenTelemetry Windows DLL, and referenced it in the php.ini file.

php -mi shows the opentelemetry has been loaded.

php -mi | grep telemetry
opentelemetry

php -r shows the function exists:

php -r "print_r(get_extension_funcs('opentelemetry'));"
Array
(
    [0] => OpenTelemetryInstrumentationhook
)

In PhpStorm’s PHP Interpreter also configured the exact PHP, as when I execute phpinfo from PhpStorm’s run button, it shows the opentelemetry in loaded. I can also get the tracing data when run the code in PhpStorm which imply the extension works.

But why PhpStorm does not recognize the function in the extension?

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to LazyOne's answer detailed explanation.

    I tried config the stub path in PhpStorm, but it not works, even when I reopen the PhpStorm or reload the interpreter.

    Finally I make a .phpstorm.stubs at the root directory of my project, and add the opentelemetry stub file as refered in answer. Then it works.

    enter image description here


  2. PhpStorm uses stub files for providing code completion (and static analysis) for functionality provided by custom PHP extensions/modules (that come from .dll / .so files).

    Stub file is a limited PHP version of those classes/methods/functions/etc with (optional) full PHPDoc block but empty bodies. Overall it’s something similar to what .h files are in C. You can Ctrl + Click on any standard PHP class/function (e.g. MySQL or str_replace()) and see yourself how it’s done (the IDE will open corresponding stub file in another editor tab). A bit more: https://stackoverflow.com/a/35923482/783119


    What you can do right now:

    1. Try the latest 2023.3 Beta build and locate and enable that extension stubs there (it should be there): https://www.jetbrains.com/phpstorm/nextversion/

    2. Using the current PhpStorm version: Get the own copy of the latest stubs repository and specify the path at Settings/Preferences | PHP | PHP Runtime | Advanced settings | Default stubs path.

      Be careful with this one though: do not forget to clear it and switch back to the bundled version when you upgrade to 2023.3 version (outdated stubs can cause other issues — providing wrong signature of the method/not recognizing newly added classes/methods etc). Or ensure to maintain the latest version of the stubs there yourself.

    3. Using any PhpStorm version: Just get that single opentelemetry.php stub file and place it anywhere in your project so it gets indexed: the IDE will use it for code completion.

      The same: when you upgrade to 2023.3 or newer version then it’s better to remove such a custom stub file and switch to the bundled stubs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search