PHP autocomplete simple project 102.114

Hi!

I am very confused. I have attached a simple project with only two files.
The first file define a simple class, while the second creates an instance of it. This is a very simple test project. But I could not use autocompletion in it. I understand that I should not open an issue. Most likely I did something wrong doing. I can anyone help? I'm at a loss.

Here is two files:


[Model.php]
<?php

namespace Core {
    
    class Model {
        function getName() {
            return \get_class($this);
        }
    }
}


[autocomplete.php]
<?php

$y= new Core\Model();
$y->getName();


In the first line of autocomplete.php autocompletion works fine for class name. From this it is expected that the project is indexed properly and that the second line autocompletion will work too. However, it is not.


WinXP SP3
PHPStorm PS-102.114

Thank you!



Attachment(s):
tv2.zip
3 comments

Hi alexey,

Tested in latest EAP build -- PS-102.206.

In autocomplete.php file you have to look at Structure tab: PhpStrom treats $y as Model .. but it should be Core\Model instead.


Add use Core\Model; to your autocomplete.php:

<?php

use Core\Model;

$y = new Core\Model();
$y->getName();

Now it works fine -- PhpStorm treats $y as Core\Model.


On another hand -- the code below can be processed by PhpStorm just fine:
Model.php

<?php

namespace Core {
    
    class Model {
        function getName() {
            return \get_class($this);
        }
        
        static function newInstance() {
            return new self();
        }
            
    }
}

autocomplete.php

<?php

$y = Core\Model::newInstance();
$y->getName();


As I'm not using namespaces in my projects I have not done any deep research into this subject and therefore cannot really advice if it is a bug, or inconsistent behavior or if it meant to be this way (i.e. PhpStorm behaves correctly and you need to use "use" clause in order for namespaces to work properly).

0

Andriy, thank you very much for this reply.First of all Structure tab explain me very much. Now it looks like PhpStorm parses namespases incorrectly.
Using "use" statements in this example is optional from php point of view.This two ways are equivalent from php point of view



<?php

$y= new Core\Model();

<?php

use Core\Model;
$y = new Core\Model();


On the other hand Nebeans parses this sources correct at all ways (screenshot). Perhaps I forgot to check some option in Settings like Netbeans "PHP Version PHP 5.3". Without this option Netbeans parses PHP 5.3 featured project incorrectly. can anyone help?

Thanks!



Attachment(s):
a.JPG
0

Hi alexey,

There is no such option in PhpStorm as it officially supports PHP v5.3.x only.

I can only suggest look trough already reported issues or create new one if nothing matches your case.

0

Please sign in to leave a comment.