Recognizing defined constants for being objects has still an another bug
pjylkka opened this issue · comments
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.
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