Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognizing defined constants for being objects has still an another bug #2865

Open
pjylkka opened this issue Apr 24, 2024 · 0 comments
Open

Comments

@pjylkka
Copy link

pjylkka commented Apr 24, 2024

Bug description
This references this (partly) fixed bug: #2330

Since last fix, this works now, no matter if it's in __construct() or not, MY_API constant will be in global scope like it should.

define("MY_API", new MyAPIObject());

BUT there's still something clitching. Here's how to reproduce the issue;

class MyClass {
    
    public MyAPIObject $Object;
    
    public function __construct() {

          define("MY_API", $this->MyAPIObject = new MyAPIObject()); 
          // MY_API will be available in global scope, and references to $this->MyAPIObject and works ok,
          // but intelephense does not recognize for being MyAPIObject instance, not within this class, or global scope 
          // - and gives no suggestions.

    }
}

Same thing happens if it's written like this:

class MyClass {
    
    public MyAPIObject $Object;
    
    public function __construct() {

          $this->MyAPIObject = new MyAPIObject();
          
          define("MY_API", $this->MyAPIObject); 
          // MY_API will be available again in global scope, but Intelephense does not recognize it
          // for being MyAPIObject instance. Not within this class, or global scope.

    }
}

I also tried to give hints to it with no success.

    public function __construct() {
           /** 
           * @var MyAPIObject $this->MyAPIObject
           * @var MyAPIObject MY_API
           */
          define("MY_API", $this->MyAPIObject); 

Also @alxgarshin has commented on closed case #2330 something that might be part of as described above

Thank you very much! Now I'm able to use a constant defined with a "new" pattern. However, it's still impossible to use a singleton pattern.

image

Expected behavior
On all these cases intelephense should recognize MY_API constant for being instance of MyAPIObject. Within object instance and global scope, as like PHP itself recognizes it.

Platform and version
Win10 / Latest Intelephense / Latest VSCodium

@pjylkka pjylkka changed the title recognizing defined constants for being Objects is still buggy Recognizing defined constants for being objects has still an another bug Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant