Closed andrew-svirin closed 3 years ago
Hi. I believe you need to bind with global $app;
to use a global variable in a function
Like:
function someName() {
global $app;
$app['twig.form.renderer']->render(); // completion should work if you bound the var with `global`
}
See: https://www.php.net/manual/en/language.variables.scope.php
$app['twig.form.renderer']=new Symfony\Bridge\Twig\Form\TwigRenderer();
$app['twig.form.renderer']->render(); //here works
function() use ($app){
$app['twig.form.renderer']->render(); //here not works
}
With global initialization do not working also (
hm... could it be that you are using a "Scratch File" for this code?
I had this issue reproducing in a Scratch File, but when I created a real index.php
file, it worked ok
I understood what the difference.
Your case is working on my code as well.
Difference is in that a have declared in another file _ide_autocomplete.php
$app['twig.form.renderer']=new Symfony\Bridge\Twig\Form\TwigRenderer();
So then autocomplete works only in global scope, but inside functions don`t.
Hm...
Yes, you again right. Then difference in another. I using framework that is very old (Silex) And here $app
also initialized like $app = Application();
so i have construction like on screen
I wonder what causes plugin to go bananas here... Not use()
per chance?
Yeah, I think it's the use()
. Can you remove $app
from the use()
list? You closure on it with global
anyway, so your app should still work...
Supporting use()
is tricky and supporting global vars is tricky - supporting use()
of global vars would be tricky^2, so better use just global
instead of use()
if possible...
This way works. Thanks a lot for assist.
First of all, thanks for your plugin.
I trying to make autocomplete for Pimple with you plugin, but i do not know how to make autocomplete
For example i have generated file
_ide_helper.php
with such records:and using in other files like this
Question: Is it possible to force autocomplete for some variable be autocompleted global?